react-practice icon indicating copy to clipboard operation
react-practice copied to clipboard

这里是不是每次onstart都会重置时间,而不是继续上次停止的时间?

Open zhangruidong opened this issue 6 years ago • 2 comments

https://github.com/mocheng/react-practice/blob/67df773606e5515ff65a062596a61c6496caae59/basic_stop_watch/src/StopWatch.js#L33

zhangruidong avatar Mar 11 '19 06:03 zhangruidong

我也发现这个问题了,每次停止后在开始都是重新计算

zzm1220 avatar Mar 29 '19 07:03 zzm1220

 onStart = () => {
    if (this.state.startTime && this.state.currentTime) {
      this.setState({
        isStarted: true,
      });
    } else {
      this.setState({
        isStarted: true,
        startTime: new Date(),
        currentTime: new Date(),
      });
    }

    this.intervalHandle = setInterval(() => {
      this.setState({ currentTime: new Date() });
    }, 1000 / 60);
  };

onStart 改造一下,可以解决这个问题。

jydeng avatar Feb 19 '21 09:02 jydeng