Deprecate useProvidedRefOrCreate and migrate everything except for hooks#7644
Deprecate useProvidedRefOrCreate and migrate everything except for hooks#7644iansan5653 wants to merge 5 commits intocreate-use-combined-refsfrom
useProvidedRefOrCreate and migrate everything except for hooks#7644Conversation
|
|
useCombinedRefshook to deprecate and replaceuseRefObjectAsForwardedRef#7638In #7638 I created a
useCombinedRefshook and migrated all instances ofuseRefObjectAsForwardedRefto it.A similar pattern is using
useProvidedRefOrCreatefor this. It's typically used with a type cast and ats-expect-errorcomment (❗):This is obviously problematic. The type errors are trying to point out the problem with this pattern: it will break if consumers pass ref callbacks. Ref callbacks are likely to become more and more common as React 19 has introduced ref callback cleanup functions, making ref callbacks a viable alternative to effects.
A much better pattern is to be consistent and use the same approach as in #7638:
NOTE: While I deprecated the
useProvidedRefOrCreatehook so that we can prepare to remove it from the public API in a future release, I didn't migrate every case and I think we'll probably want to keep it around in an undeprecated internal API. The cases where it still applies are very specific to utility hooks likeuseAnchoredPosition. These are expected to accept and return ref objects and would require significant breaking changes to make them compatible withuseCombinedRefssince they'd have to return callback refs.Changelog
New
Changed
Removed
Rollout strategy
Testing & Reviewing
Merge checklist