is there any way to reset this timer if modal boolean is false?
I want it to work only if modal appears, and reset immediately after modal is closed.
useEffect(() => {
if (modal) {
const timer = setInterval(() => {
if (countRef.current >= 10) {
clearInterval(timer);
} else {
setCount((count) => count + 1);
}
}, 1000);
}
if (!modal) {
clear interval here and reset counter, is this possible?
}
}, [modal]);