@KamQuoss
Posted
Hi Claire, nice work :) I've noticed that numbers aren't changing every second, but change is made every 2-4 seconds. Have You tried to count time with Date object and interval. Chcecking current time and calulating subtraction from "zero" every second (interval) could be more accurate. Hope this apprach would be interesting for You.
Marked as helpful
@ClaireKarsenti
Posted
@KamQuoss
Oops! Thanks for flagging this ๐ Considering this, I've just updated my code with a new useEffect for my useTimer hook:
useEffect(() => {
const initialInterval: any = setInterval(() => {
setTimeSpan((prevCount) => prevCount - SECOND);
}, SECOND);
if (!isStarted) {
clearInterval(initialInterval);
}
if (timeSpan === 0) {
setTimeIsUp(true);
clearInterval(initialInterval);
return;
}
return () => clearInterval(initialInterval);
}, [timeSpan, isStarted, interval]);
Thank you ๐