[英]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.