-2
なぜclearIntervalが機能しないのですか? 初めて動作したときに "Here"が出力され、同時に動作する2番目のタイマーが作成されます。なぜこのclearIntervalが機能しないのですか?
runTimer() {
let _this = this
let intervalID
if (this.state.didTimerRun === false) {
this.state.didTimerRun = true
intervalID = setInterval(function() {
if (_this.state.seconds !== 0) {
_this.setState({
seconds: _this.state.seconds - 1,
})
} else if (_this.state.seconds === 0) {
_this.setState({
seconds: 60,
workTime: _this.state.workTime - 1
})
}
}, 1000)
} else {
console.log('Here')
clearInterval(intervalID)
_this.setState({
workTime: 25,
seconds: 0,
didTimerRun: false
})
}
}