-
Notifications
You must be signed in to change notification settings - Fork 1k
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
chore(react): use updater
callback function
#6424
chore(react): use updater
callback function
#6424
Conversation
callback takes the previous state as the first argument. > setState() does not always immediately update the component. It may batch or defer the update until later. This makes reading this.state right after calling setState() a potential pitfall. Instead, use componentDidUpdate or a setState callback (setState(updater, callback)), either of which are guaranteed to fire after the update has been applied. If you need to set the state based on the previous state, read about the updater argument below. see: - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md - https://reactjs.org/docs/react-component.html#setstate
e47bd1c
to
f327737
Compare
Seeing some odd test failures. Seems like maybe a flakey test?
https://github.com/redwoodjs/redwood/actions/runs/3101321311/jobs/5022567567#step:8:1475 |
c6eaf31
to
37f26b2
Compare
Still seeing some odd test results: https://github.com/redwoodjs/redwood/actions/runs/3101811253/jobs/5023535465#step:8:1287
not quite sure what is going on, but this one seems like an actual regression. |
All tests passed now, so I went ahead and merged. I've not been all to happy about the state of our regression tests lately though, randomly failing more often than not 🙁 So I think it's probably worth it soon to see if we can do something about that |
+💯 - As a small related aside, I have found my work on #4992 is rife w/ what look to be test failures due to flakey / poorly written tests. |
callback takes the previous state as the first argument.
see:
Closes #5627