Tell us what’s happening:
Hey guys, I’m doing the 25-5 clock in the Front End Development Libraries course, and I’m trying to use the React useEffect hook to make the timer re-render every second. I expected the below code to re-render a decremented value every second, but it is causing a decrement and re-render dozens of times per second, and leading to maximum depth exceeded. Where have I gone wrong?
Your code so far
useEffect(() => {
if (isRunning) {
setTimeout(setTimeLeft(timeLeft - 1), 1000);
}
}, [timeLeft, isRunning]);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Challenge: Front End Development Libraries Projects - Build a 25 + 5 Clock
Link to the challenge: