Created
August 11, 2017 00:33
-
-
Save treyhuffine/7d765929f0ccee29110017eca0882c56 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 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