Last active
June 13, 2017 13:56
-
-
Save coryhouse/672902ef5e6ff46374f6d560dca8b64a to your computer and use it in GitHub Desktop.
Example of improperly referencing state immediately after callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateState({target}) { | |
this.setState({user: {...this.state.user, [target.name]: target.value}}); | |
doSomething(this.state.user) // Uh oh, setState merely schedules a state change, so this.state.user may still have old value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment