I have this component:
const deployIntervalRef = useRef(null);
useEffect(() => {
deployIntervalRef.current = setInterval(() => {
console.log("interval handler");
console.log(deployIntervalRef.current);
clearInterval(deployIntervalRef.current);
deployIntervalRef.current = null;
},2000);
}, []);
In my mind, it should output “interval handler” once and then stop,but it doesn’t. Why?
From the second log, you can see that when clear, ref has an interval id