Skip to content

useState has something wrong in devtools if used with useContext and useEffect. #15430

@zhengxiaoyao0716

Description

@zhengxiaoyao0716

Do you want to request a feature or report a bug?
bug

What is the current behavior?
The useState got an unexpected state like {tag: 192, create: ƒ, destroy: undefined, deps: Array(0), next: {…}} when we open the Chrome devtools and select the mounted node.

Here the test code:

import React, { createContext, useContext, useEffect, useState } from 'react';
import ReactDOM from 'react-dom';

const TestContext = createContext();

const useTest = () => {
    const context = useContext(TestContext) || {};
    useEffect(() => { console.log(context); }, []);

    const [state, _setState] = useState(null);
    console.log(state);
};

const Test = () => {
    useTest();
    return <div></div>;
};

ReactDOM.render(<Test/>, document.getElementById('root'));

Then if we open the Chrome devtools and click the Test node, we can see the useState returns an unexpected state:
image

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
OS:

Microsoft Windows [版本 10.0.15063]

React:

    "react": "^16.8.3",
    "react-dom": "^16.8.3",

Chrome:

版本 72.0.3626.109(正式版本) (64 位)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions