📌  相关文章
📜  删除 React 中未安装组件上的 setState 警告 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:18.736000             🧑  作者: Mango

代码示例2
function useAsync(asyncFn, onSuccess) {
  useEffect(() => {
    let isActive = true;
    asyncFn().then(data => {
      if (isActive) onSuccess(data);
    });
    return () => { isActive = false };
  }, [asyncFn, onSuccess]);
}