const PomView = () => { const [timer, setTimer] = useState(1500); // 25 minutes const [start, setStart] = useState(false); const firstStart = useRef(true); const tick = useRef(); // <-- React ref useEffect(() => { if (firstStart.current) { firstStart.current = !firstStart.current; return; } if (start) { tick.current = setInterval(() => { setTimer((timer) => timer - 1); }, 1000); } else { clearInterval(tick.current); } return () => clearInterval(tick.current); }, [start]); };