Commit 00278519 authored by dong's avatar dong Committed by niko

repair problem: countdown will not change when target time update (#392)

parent 9d9025a5
...@@ -21,9 +21,12 @@ class CountDown extends Component { ...@@ -21,9 +21,12 @@ class CountDown extends Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.target !== nextProps.target) { if (this.props.target !== nextProps.target) {
clearTimeout(this.timer);
const { lastTime } = this.initTime(nextProps); const { lastTime } = this.initTime(nextProps);
this.setState({ this.setState({
lastTime, lastTime,
}, () => {
this.tick();
}); });
} }
} }
...@@ -76,18 +79,18 @@ class CountDown extends Component { ...@@ -76,18 +79,18 @@ class CountDown extends Component {
clearTimeout(this.timer); clearTimeout(this.timer);
this.setState({ this.setState({
lastTime: 0, lastTime: 0,
}); }, () => {
if (onEnd) { if (onEnd) {
onEnd(); onEnd();
} }
});
} else { } else {
lastTime -= this.interval; lastTime -= this.interval;
this.setState({ this.setState({
lastTime, lastTime,
}); }, () => {
this.tick(); this.tick();
});
} }
}, this.interval); }, this.interval);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment