From 002785190e49ad32e8c590351ff47f288eb9b778 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 8 Dec 2017 18:27:28 +0800 Subject: [PATCH] repair problem: countdown will not change when target time update (#392) --- src/components/CountDown/index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/CountDown/index.js b/src/components/CountDown/index.js index f7caec22..e1e85bc2 100644 --- a/src/components/CountDown/index.js +++ b/src/components/CountDown/index.js @@ -21,9 +21,12 @@ class CountDown extends Component { componentWillReceiveProps(nextProps) { if (this.props.target !== nextProps.target) { + clearTimeout(this.timer); const { lastTime } = this.initTime(nextProps); this.setState({ lastTime, + }, () => { + this.tick(); }); } } @@ -76,18 +79,18 @@ class CountDown extends Component { clearTimeout(this.timer); this.setState({ lastTime: 0, + }, () => { + if (onEnd) { + onEnd(); + } }); - - if (onEnd) { - onEnd(); - } } else { lastTime -= this.interval; this.setState({ lastTime, + }, () => { + this.tick(); }); - - this.tick(); } }, this.interval); } -- GitLab