Add a concurrent mode safe version of useRefs #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 asuseLayoutEffect
, 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.