-
-
Save amogower/ca248da3fa7254e239d1cd79cf700799 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... | |
doSomething(updatedUser); // Now I can safely utilize the new state I've created to call other funcs... | |
return { user: updatedUser }; // And what I return here will be set as the new state | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment