Skip to content

Instantly share code, notes, and snippets.

@SangeetAgarwal
Last active August 23, 2018 12:03
Show Gist options
  • Save SangeetAgarwal/264a1b4a83fa85d7982492b3de6c21c8 to your computer and use it in GitHub Desktop.
Save SangeetAgarwal/264a1b4a83fa85d7982492b3de6c21c8 to your computer and use it in GitHub Desktop.
callbackFromOfSetState
updateState({target}) {
this.setState((prevState) => {
const updatedUser = {...prevState.user, [target.name]: target.value}; // use previous value in state to build new state...
return { user: updatedUser }; // And what I return here will be set as the new state
}, () => this.doSomething(this.state.user); // Now I can safely utilize the new state I've created to call other funcs...
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment