-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Bug: using useState without changing the state generate a useless rerender #18761
Comments
Same problem. When removing React.StrictMode it solves the problem |
When removing useState and useEffect it solves the problem,too. |
Removing the component solves the problem too xD |
haha~, you make me laugh... |
Source: #15074 (comment) |
Ok, my bad then. I didn't know at all about this feature. Should strict mode log a message in develpment to warn about this or anything? I think it is hard for devs to discover about the source of what they may experience in the current state of things. |
Cool, thanks for sharing. I learned something new. Side effects in render-phase lifecycle methods will break when enabling Concurrent mode. https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects |
I can confirm this is fixed in #18547 and the fix will be included in React 17. To be clear, the component will still run twice, but the |
To clarify, there was no bug here, and so nothing was fixed. The behavior is as intended: StrictMode calls your component function twice to help find accidental mutations and side effects. |
When using useState in a component, this component will rerender twice, whereas nor the state nor the props did change.
React version: 16.13.1
Steps To Reproduce
Link to code example: codesandbox
The current behavior
Logs are:
render 1
render 2
The expected behavior
render 1
The text was updated successfully, but these errors were encountered: