简体   繁体   English

React 文档中 useEffect 中缺少依赖项数组

[英]Missing dependency array in useEffect in React docs

My question is simple, why isn't there a dependency array here https://reactjs.org/docs/hooks-custom.html我的问题很简单,为什么这里没有依赖数组https://reactjs.org/docs/hooks-custom.html

Shouldn't this results in unnecessary subscribes and unsubscribes?这不应该导致不必要的订阅和取消订阅吗? Will passing props.friend.id result in different behavior?传递 props.friend.id 会导致不同的行为吗?

useEffect without the dependency array will run on each component update.没有依赖数组的useEffect将在每次组件更新时运行。

If we consider that ChatAPI will just do nothing on repeated subscription, we don't necessarily need to pass the dep.如果我们认为 ChatAPI 在重复订阅时不会做任何事情,我们不一定需要通过 dep。 array.大批。

Found my closure here https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects .在这里找到我的关闭https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skiping-effects

So passing dep was the right way, I guess they left it out for the sake of simplicity.所以传递 dep 是正确的方法,我想他们为了简单起见就把它省略了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Hook useEffect 缺少依赖数组 - React Hook useEffect has a missing dependency array React Hook useEffect 缺少依赖项 - missing dependency for React Hook useEffect UseEffect - React Hook useEffect 缺少依赖项: - UseEffect - React Hook useEffect has a missing dependency: React Hook useEffect 缺少对 useEffect 的依赖 - React Hook useEffect has a missing dependency with useEffect React Hook useEffect 缺少依赖项:'formData'。 包括它或删除依赖项数组。 什么是依赖就是使用 - React Hook useEffect has a missing dependency: 'formData'. Either include it or remove the dependency array. what is dependency is use React Hook useEffect 缺少一个依赖项:'handleLogout'。 要么包含它,要么移除依赖数组 react - React Hook useEffect has a missing dependency: 'handleLogout'. Either include it or remove the dependency array react React hook useEffect 依赖数组 - React hook useEffect dependency array React Hook useEffect 缺少依赖项:“match.params.roomid”。 包含它或删除依赖项数组 - React Hook useEffect has a missing dependency: 'match.params.roomid'. Either include it or remove the dependency array React Hook useEffect 缺少依赖项:'fetchTracker'。 包括它或删除依赖项数组 - React Hook useEffect has a missing dependency: 'fetchTracker'. Either include it or remove the dependency array React Hook useEffect 缺少依赖项:'id'。 包括它或删除依赖数组 - React Hook useEffect has a missing dependency: 'id'. Either include it or remove the dependency array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM