|
|
@@ -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);
|
|
|
}
|