From 7e80d0189a29220a325ec1c22e76e1976ef1cb47 Mon Sep 17 00:00:00 2001 From: "dolev.ben-aharon" Date: Fri, 20 Sep 2019 16:29:41 +0300 Subject: [PATCH] Refactor componentWillReceiveProps() to componentDidUpdate(). --- lib/stopwatch.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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); }