Last active
March 4, 2019 06:07
-
-
Save behnamazimi/0b15abf9cfa5bcc9bbb7f8469d94ce1a to your computer and use it in GitHub Desktop.
Immutability Helpers Clean Code
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
// Dirty Code | |
const { Obj2 } = this.state | |
Obj2.value = "new value" | |
this.setState({ | |
Obj2 | |
}) | |
// Clean Code | |
this.setState(update(this.state, { | |
Obj2: { value: { $set: "new value" }} | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment