Skip to content

Instantly share code, notes, and snippets.

@Tin-Nguyen
Last active April 13, 2017 21:14
Show Gist options
  • Save Tin-Nguyen/e44d2286e7ccccf336c72ab33a50122a to your computer and use it in GitHub Desktop.
Save Tin-Nguyen/e44d2286e7ccccf336c72ab33a50122a to your computer and use it in GitHub Desktop.
class CounterButton extends React.Component {
constructor(props) {
super(props);
this.state = {count: 1};
}
shouldComponentUpdate(nextProps, nextState) {
return (this.props.color !== nextProps.color) ||
(this.state.count !== nextState.count);
}
render() {
return (
<button
color={this.props.color}
onClick={() => this.setState(state => ({count: state.count + 1}))}>
Count: {this.state.count}
</button>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment