Skip to content

Commit

Permalink
add shouldComponentUpdate to CountDown
Browse files Browse the repository at this point in the history
  • Loading branch information
mocheng committed Dec 31, 2016
1 parent ab4139a commit cc9841c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chapter-06/function_as_child/src/CountDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class CountDown extends React.Component {
this.state = {count: this.props.startCount};
}

shouldComponentUpdate(nextProps, nextState) {
return nextState.count !== this.state.count;
}

componentDidMount() {
this.intervalHandle = setInterval(() => {
const newCount = this.state.count - 1;
Expand Down

0 comments on commit cc9841c

Please sign in to comment.