Closed skyliwq closed 1 month ago
刷新之后useEffect重新执行设置新的定时器
After refreshing, useEffect will re-execute to set a new timer.
useEffect(()=>{
const interval = setInterval(()=>{
console.log('interval');
},1000);
return ()=>{
console.log('clear interval ---------------');
clearInterval(interval);
}
},[])
考虑一下你的设置定时器逻辑,在什么情况下不用设置 Consider your logic for setting timers: when would you not need to set one.
谢谢,是我的疏忽
我设置了定时器,在刷新 refresh 缓存后依旧执行,无法在 useEffect(() => { return clearInterval(intervalRef.current) }, []) 销毁
I set a timer, and it continues to execute after refreshing the cache. It cannot be destroyed in useEffect(() => { return clearInterval(intervalRef.current) }, []).