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 a concurrent mode safe version of useRefs #2

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

ZachHaber
Copy link
Contributor

Only difference is that refs are applied at the same time as layoutEffects, so its slower to apply.

I thought I had a good solution for fixing the concurrent mode issue and keeping the ability to work with layoutEffects. Unfortunately, useImperativeHandle runs at the same timing as useLayoutEffect, so in this case it would just require more boilerplate for no improvement over a layoutEffect.

Theoretically, if I set the proxiedRef to have the current refs on first mount, as long as you don't change the refs, it will work for layout effects, but I think it might make sense to either make it always work for layout effect (probably not safe for concurrent mode) or make it always not work for layout effects (probably safer for concurrent mode).

If the React team changes the timing of useImperativeEffect to be at the same time as the normal DOM ref setting, then I think we could get it fully settled in user-land, but I think it would still be better and safer for them to just make refs merge automatically in the library.

Only difference is that refs are applied at the same time as layoutEffects, so its slower to apply.
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

Successfully merging this pull request may close these issues.

2 participants