Skip to content

Instantly share code, notes, and snippets.

@darrylhebbes
Created June 12, 2020 09:51
Show Gist options
  • Save darrylhebbes/1c4665133f93703a35df900fb0c12fd7 to your computer and use it in GitHub Desktop.
Save darrylhebbes/1c4665133f93703a35df900fb0c12fd7 to your computer and use it in GitHub Desktop.
state update
//
const updateState = (valueToUse): void => {
this.setState(prevState => ({
jasper: {
// object that we want to update
...prevState.jasper, // keep all other key-value pairs
name: valueToUse // update the value of specific key
}
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment