-
Notifications
You must be signed in to change notification settings - Fork 50.9k
useState has something wrong in devtools if used with useContext and useEffect. #15430
Copy link
Copy link
Closed
Closed
Copy link
Description
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:

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 位)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels