Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Last active June 13, 2017 13:46
Show Gist options
  • Save coryhouse/84877b5ce8b61f66d3f15a02e7b365ce to your computer and use it in GitHub Desktop.
Save coryhouse/84877b5ce8b61f66d3f15a02e7b365ce to your computer and use it in GitHub Desktop.
Bad example of updating state in React by mutating it before calling setState
updateState(event) {
 const {name, value} = event.target;
 let user = this.state.user; // this is a reference, not a copy...
 user[name] = value; // so this mutates state 🙀
 return this.setState({user});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment