reactn
reactn copied to clipboard
useEffect in useGlobal has no dependencies and will run every render
The function to add the global listener in useEffect
will be rerun in every render since no dependency array is provided:
https://github.com/CharlesStover/reactn/blob/master/src/use-global.ts#L69-L83
Is this intentional?
I'm unsure. useGlobal
isn't very standardized, since it has conditional hook usage which is not a great practice, but solved a problem here. It could be that the effect every render solved an edge case bug, or it could have been an oversight!
If this isn't causing a performance bottleneck for your application, I'd recommend leaving it as-is so as not to introduce edge case bugs on the off-chance it'd cause any.
Any future releases of ReactN will contain the hooks lint rule that would prevent this from happening. 😄
Thanks for bringing it to my attention. I'll leave this ticket open, because it's a valid issue; but there's currently no incentive to fix it. Let me know if this is causing you any issues.