Last active
June 13, 2017 13:46
-
-
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
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(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