react-practice
react-practice copied to clipboard
这里是不是每次onstart都会重置时间,而不是继续上次停止的时间?
https://github.com/mocheng/react-practice/blob/67df773606e5515ff65a062596a61c6496caae59/basic_stop_watch/src/StopWatch.js#L33
我也发现这个问题了,每次停止后在开始都是重新计算
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 改造一下,可以解决这个问题。