yuchi / hooks.macro

☔️ Babel Macros for automatic React Hooks memoization invalidation
MIT License
357 stars 5 forks source link

Known static return value from react-redux hook #13

Closed Glinkis closed 4 years ago

Glinkis commented 4 years ago

I'm pretty sure the useDispatch hook in the react-redux package returns a referentially equal value every time, so it should be safe to omit it from the dependency arrays.

Here is the source for this hook.

yuchi commented 4 years ago

Thank you for your suggestion! I was thinking about that just yesterday and if you dig deeper you’ll discover that dispatch is essentially useContext(…).store.dispatch. Contexts are not inherently static, you can literally change the store at runtime in this specific case, and adding them to the “known static values” would produce extremely obscure bugs.

Let me close the issue as wontfix for these reasons, and reopen it if you think I got something wrong.