Trying to pause a setInterval timer (React)

This is in ReactJS.

I am doing a pomodoro clock project and I am using a setInterval timer in order to make the clock tick. I tried using clearInterval(func) where func was the name of the variable i assigned the setInterval to. It seems to simply not work and my timer continues to tick and I am unsure what I have wrong in my code. The relevant area in code are lines 64 to 78 with my startPause function. Disreguard the fact that the visual timer counts down horribly incorrectly, Im getting there but I want to make the start / pause button work correctly first. The more you press the start button, the more frequently the timer counts down telling me its starting more countdowns all under the variable name interval.

CodePen: https://codepen.io/AugustTGuenther/pen/qBZLVxr

Look var interval in else statement is undefined . It means when you click pause there is no interval store in your variable so you can make state to save intervalId and use this state to pause the timer

1 Like

Ahhhh I see, I did not realize you could store that in the state. Thank you very much!

1 Like

You are welcome :slight_smile: .