Last active
August 23, 2018 12:03
-
-
Save SangeetAgarwal/264a1b4a83fa85d7982492b3de6c21c8 to your computer and use it in GitHub Desktop.
callbackFromOfSetState
This file contains 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((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