最佳答案
如果我们想要限制 useEffect
只在组件安装时运行,我们可以添加 useEffect
的第二个参数与 []
。
useEffect(() => {
// ...
}, []);
但是,除了初始挂载之外,我们如何才能使 useEffect
仅在组件更新的时刻运行呢?