Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Created August 11, 2017 00:33
Show Gist options
  • Save treyhuffine/7d765929f0ccee29110017eca0882c56 to your computer and use it in GitHub Desktop.
Save treyhuffine/7d765929f0ccee29110017eca0882c56 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) {
if (this.props.color !== nextProps.color) {
return true;
}
if (this.state.count !== nextState.count) {
return true;
}
return false;
}
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