krvajal / use-intercom-hook

5 stars 2 forks source link

Loaded part of the dependency array #1

Closed benoror closed 5 years ago

benoror commented 5 years ago

Shouldn't loaded be part of the dependency array?

https://github.com/krvajal/use-intercom-hook/blob/999f19bb6fcf0394159cc0ccff693c8dd66aa6f0/src/index.js#L45

If you use this optimization, make sure the array includes all values from the component scope (such as props and state) that change over time and that are used by the effect. Otherwise, your code will reference stale values from previous renders. Learn more about how to deal with functions and what to do when the array changes too often.

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

We recommend using the exhaustive-deps rule as part of our eslint-plugin-react-hooks package. It warns when dependencies are specified incorrectly and suggests a fix.

This is how I noticed it

benoror commented 5 years ago

Closing and that actually will double-trigger the effect