No values reported when using React StrictMode
See original GitHub issueHi,
I am using this hook in one of my projects in conjunction with React 18 and Strict Mode. However, it appears that the hook does not report any values when used together with React Strict Mode.
See the following CodeSandbox for a demonstration of this issue.
This issue is caused by the fact that React Strict Mode renders components twice in development mode in order to detect problems. In particular, this behavior causes problems with the following logic (for tracking unmounts):
Because the component is rendered twice, the component is marked as unmounted and no further size updates are reported by the hook.
I believe the following patch should resolve this issue:
const didUnmount = useRef(false);
useEffect(() => {
+ didUnmount.current = false;
return () => {
didUnmount.current = true;
};
}, []);
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Using strict mode in React 18: A guide to its new behaviors
Strict mode is trying to be future-ready with React's suspense-based architecture, making it more resilient for introspecting UI issues.
Read more >Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI. It activates...
Read more >Bug: React 18 Strict mode does not simulate unsetting and re ...
Refs that store use-managed values won't be reset when a component is hidden though. They allow things to be persisted for the case...
Read more >My React Component is rendering twice because of Strict Mode
StrictMode renders components twice (on dev but not production) in order to detect any problems with your code and warn you about them ......
Read more >What is StrictMode in React ? - GeeksforGeeks
StrictMode is a React Developer Tool primarily used for highlighting possible problems in a web application.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
🎉 This issue has been resolved in version 9.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
Hopefully I’ll have some time this weekend to wrap things up 🤞