Answer the question
In order to leave comments, you need to log in
How to properly clear the interval?
Hello. I have a counter implementation. When you press the "start" button, the stopwatch should start and after a specified time interval increase its value by the value of the interval. When you click on "stop", the stopwatch should stop and reset its value
The problem is the following, please tell me how to reset setInterval correctly
handleStop = () => {
this.setState({ currentTime: 0 })
}
Answer the question
In order to leave comments, you need to log in
Before learning React, it is imperative that you first learn VanillaJS. In the documentation forThe setInterval explicitly states that the setInterval identifier must be passed to clearInterval , which is also written in the answers to the question at the link you provided in the comment to the previous answer. No need to reinvent the wheel, take and use what you have.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question