My timer will not stop at zero. It seems like it should be simple.
I am trying to set up my timer as follows:
const [ seconds, setSeconds ] = useState(5)
const interval = setInterval(() => {
if (seconds > 0) {
setSeconds((seconds) => seconds - 1)
} else {
clearInterval(interval)
}
}, 1000);
I'm also rendering the seconds on the front end. Why won't the timer stop at zero? It continues counting into negative numbers.