简体   繁体   中英

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

Shouldn't this results in unnecessary subscribes and unsubscribes? Will passing props.friend.id result in different behavior?

useEffect without the dependency array will run on each component update.

If we consider that ChatAPI will just do nothing on repeated subscription, we don't necessarily need to pass the dep. array.

Found my closure here https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects .

So passing dep was the right way, I guess they left it out for the sake of simplicity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM