Last active
August 23, 2018 14:26
-
-
Save coryhouse/b86869639f34c3f91cbefacfc9f84372 to your computer and use it in GitHub Desktop.
Callback setState example
This file contains hidden or 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