This is my react code. It makes the component re-render infinitely:
const [seconds, setSeconds] = useState(60) useEffect(() => { const interval = setInterval(() => { setSeconds(seconds => seconds - 1); }, 1000); return () => clearInterval(interval); }, []); console.log("object");
This happens because you only clear the interval when the component unloads, which only happens when the user navigates away from the page.
Maybe this is what you need? When the interval reaches 0, I clear it. But for this I have to use reference, I can't use state from setInterval because it only has initial value: