You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useEffect(()=>{letcanceled=falsefetchData(pageIindex).then(resp=>{if(canceled){return;}// DO SOMETHING UI UPDATE});return()=>canceled=true;},[pageIndex]);
React 异步操作回收
计时器回收
计时器我们可以用对应的注销方法来回收计时器的异步回调
插桩回收
针对 Promise 这类没有原生回收方案的的异步操作,比较通用的方法是插桩回收
上面的代码,定义了一个标志位(canceled),通过函数闭包在异步回调的时候,判断是否标志位已经过期(canceled = true),如果过期,不执行回调。
The text was updated successfully, but these errors were encountered: