React hooks tip: Prefer primitives in dependency arrays


React hooks tip: Prefer primitives in dependency arrays.

Doing so helps avoid needless re-runs.

#react

I should have mentioned: Instead of passing a primitive, you can specify an object property in the dependency array if you prefer. That also works fine as shown in this sandbox I just made.

I prefer the clarity of passing primitives though.

https://codesandbox.io/s/muddy-cdn-rgw38y?file=/src/App.js

View original on X