diff --git a/lib/stopwatch.js b/lib/stopwatch.js index c59be85..361fe98 100644 --- a/lib/stopwatch.js +++ b/lib/stopwatch.js @@ -52,17 +52,22 @@ class StopWatch extends Component { } } - componentWillReceiveProps(newProps) { - if(newProps.start) { - this.start(); - } else { - this.stop(); + + componentDidUpdate(prevProps,prevState){ + if (prevProps.start !== this.props.start) { + if(this.props.start){ + this.start(); + } else { + this.stop(); + } } - if(newProps.reset) { - this.reset(); + if (prevProps.reset !== this.props.reset) { + if(this.props.reset) { + this.reset(); + } } } - + componentWillUnmount() { clearInterval(this.interval); }