Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add*Effect() cleanup callbacks called incorrectly with non-simple dependencies #81

Open
helixbass opened this issue Jun 14, 2022 · 0 comments

Comments

@helixbass
Copy link
Owner

As @peterstuart ran into, currently if you pass either a dependencies array containing a path (eg ['user.isAuthorized']) or a callback-style dependency argument to useEffect() (and I think the same would be true for useLayoutEffect()) which returns a cleanup callback, the cleanup callback isn't called at the correct time because from React's view of the world it's re-running the effect on every render (not just when the dependencies have "changed")

It looked like it would be possible to modify the implementation to avoid this for path-style dependency arrays but the problem seems more fundamental for callback-style dependency arguments

The workaround is to "pre-compute" (eg via an addProps()) a top-level prop that can then be passed as a "simple" dependencies argument array to addEffect()

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

No branches or pull requests

1 participant