Skip to content

Instantly share code, notes, and snippets.

@squalvj
Created September 14, 2018 15:39
Show Gist options
  • Save squalvj/3542f7746e1a5e99a8ad93c147673103 to your computer and use it in GitHub Desktop.
Save squalvj/3542f7746e1a5e99a8ad93c147673103 to your computer and use it in GitHub Desktop.
React, SetState Callback
_onClickHandler: function _onClickHandler() {
console.log('State before (_onClickHandler): ' + JSON.stringify(this.state));
this.setState({
dollars: this.state.dollars + 10
}, () => {
console.log('Here state will always be updated to latest version!');
console.log('State after (_onClickHandler): ' + JSON.stringify(this.state));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment