-
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
Calling setState during component rendering causes incorrect previous state value in next state update #14849
Comments
This is a bug. |
I get why this can be surprising, though I was under the impression that one should not call |
We always want to fix bugs soon. :-) There’s no need to add extra pressure — we do feel guilty around bugs in the wild and try to fix them as soon as possible. We expect to cut a fix some time next week. |
Sorry, i didn't wanted it to sound like that (i'm still sometimes struggle with speaking/writing english). React team done an amazing work on hooks, thanks all of you for that. I think that this would be preferebale solution for avoiding this bug until it will be fixed. |
Is this the same problem as described in this issue? https://codesandbox.io/s/50k546knwk When you click on button, the count will reset to Then when you uncomment the Funny is that it works with |
Should be fixed by #14852 which was just merged into master |
Is there a way install React at a particular commit on master to test it out? I think this bug is causing my rendering issues, but it would be great to know for sure so I can either wait for the release or keep digging. |
@jaydenseric How to install NPM modules from GitHub is a pretty common question, check out this thread. |
@lukewlms thanks for the tip, but I know how that works; I support Git install for the packages I publish. I don't think it will work here, since React is a monorepo of packages and the |
I've just published a canary release that includes the bugfix. You can install it by updating your React deps to
or more specifically
|
I've confirmed that the test case posted by @hlousekv works in the canary: https://codesandbox.io/s/wn23y2yx9k Assuming we don't find any additional issues, we're aiming to release a patch tomorrow. |
Fixed in 16.8.3. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Counter value is 1.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/7jzwjm090j
What is the expected behavior?
Counter value should be 2.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Firefox/Chrome
16.8.1
The text was updated successfully, but these errors were encountered: