-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The number of console.log calls in setState is incorrect #21126
Comments
In StrictMode React rerenders the app two times (in dev mode) to detect and warn if there are side-effects while rendering. |
@a-c-sreedhar-reddy thank you, this is a problem not a bug, this issus can be closed. |
We've changed the logging behavior to be more intuitive in React 18. |
Hello, I'm confused about how useState and setState work, for a simple example:
You can use this prepared code example:https://codesandbox.io/s/goofy-sea-6evwt?file=/src/App.js
React StrictMode:
local log
andglobal log
print once each.local log
prints once, butglobal log
prints twice.General mode:
local log
andglobal log
print once each.And I know React uses a cycle linked-list to store the updater,and call all updaters in a loop during the update phase the source code,
So in strict mode, what does React do to the 'local'
console.log
and why does it only print once.Is this a bug or a question ?
The text was updated successfully, but these errors were encountered: