Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

useEffect in useGlobal has no dependencies and will run every render #180

Open
dlee opened this issue Mar 6, 2021 · 1 comment
Open

Comments

@dlee
Copy link

dlee commented Mar 6, 2021

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?

@quisido
Copy link
Collaborator

quisido commented Mar 7, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants