This is the logic behind my ‘play/pause’ functionality. Does anyone know why it isn’t working? The timer seems to spasm out whenever I click the button. Much help would be appreciated!
This is so that on line 83, a message will display either ‘Play’ or ‘Pause’ depending on whether you click it the first time (meaning isPlaying is set to true and thus ‘Pause’ is displayed).
On line 40 and 49, I modify onBreak so that the code on 79-81 can display the correct message.
For 1, setIsPlaying changes the value of isPlaying, so every second you are toggling the value of isPlaying. I don’t think this is what you want to do. This value should only be set when either the play/pause or reset button is clicked, right?
Sorry, I overlooked that.
I think you need to reconsider how you are handling the timer countdown. You should probably have a separate state variable for the countdown. Also, useEffect is creating a new setInterval every time but you aren’t clearing the old one. So every time you pause/play you are adding a new timer.