Skip to content

Instantly share code, notes, and snippets.

@reime005
Created December 27, 2020 22:26
Show Gist options
  • Save reime005/1b327a93f09c708f21147a45c9ce5dd6 to your computer and use it in GitHub Desktop.
Save reime005/1b327a93f09c708f21147a45c9ce5dd6 to your computer and use it in GitHub Desktop.
// not so good
console.log(this.state.test); // 5
this.setState({ test: 12 });
console.log(this.state.test); // might be 5 or 12
// good
this.setState({ test: 42 }, () => { console.log(this.state.test); // 42 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment