Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
In concurrent mode, useMemo and useState appear to be initialized twice.
What is the expected behavior?
useMemo callback is only called when dependencies change anduseState initializer is only called once. https://codesandbox.io/s/upbeat-glade-cndru
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
0.0.0-experimental-f6b8d31a7
This bug only happens in concurrent mode. Legacy mode works as expected.
This is expected behavior for development builds and Concurrent Mode. React will call certain functions twice in development to help find potential side effects in functions that should be pure, such as useMemo and useState initializers here.
You can see the same behavior in legacy mode with React.StrictMode and read more about it in the Strict Mode documentation.
Most helpful comment
This is expected behavior for development builds and Concurrent Mode. React will call certain functions twice in development to help find potential side effects in functions that should be pure, such as
useMemoanduseStateinitializers here.You can see the same behavior in legacy mode with
React.StrictModeand read more about it in the Strict Mode documentation.