Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Last active June 13, 2017 13:56
Show Gist options
  • Save coryhouse/672902ef5e6ff46374f6d560dca8b64a to your computer and use it in GitHub Desktop.
Save coryhouse/672902ef5e6ff46374f6d560dca8b64a to your computer and use it in GitHub Desktop.
Example of improperly referencing state immediately after callback
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