I want to know what happened if I define setInterval function repeatedly to same variable in react hook useEffect.
I checked variable have new setInterval id value every defining.
But I wonder is there instance remained in memory about previous setInterval timer, even if new setInterval defined at same variable??
useEffect(() => {
const timer = setInterval(
() => {
if (count < elementLength - 1) {
boolean.current = false;
setCount(prev => prev + 1);
} else {
boolean.current = true;
setCount(0);
}
},
boolean.current ? 50 : 2500
);
return () => {
clearInterval(timer);
};
}, [count]);