Last active
July 12, 2016 11:36
-
-
Save kazagkazag/8b7099405182b8ec022d0dcd5ea15510 to your computer and use it in GitHub Desktop.
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
| class MyComponent extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { value: { foo: 'bar' } }; | |
| } | |
| onClick() { | |
| var value = this.state.value; | |
| value.foo += 'bar'; // value is reference to the current state, so current state and next state will be the same in next SCU call... | |
| this.setState({ value: value }); | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <InnerComponent value={this.state.value} /> | |
| <a onClick={this.onClick}>Click me</a> | |
| </div> | |
| ); | |
| } | |
| } | |
| class InnerComponent extends Component { | |
| shouldComponentUpdate(next, previous) { | |
| return next !== previous; | |
| } | |
| //other stuff | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment