Skip to content

Instantly share code, notes, and snippets.

@kazagkazag
Last active July 12, 2016 11:36
Show Gist options
  • Select an option

  • Save kazagkazag/8b7099405182b8ec022d0dcd5ea15510 to your computer and use it in GitHub Desktop.

Select an option

Save kazagkazag/8b7099405182b8ec022d0dcd5ea15510 to your computer and use it in GitHub Desktop.
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