Last active
April 13, 2017 21:14
-
-
Save Tin-Nguyen/e44d2286e7ccccf336c72ab33a50122a 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) { | |
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