-
Notifications
You must be signed in to change notification settings - Fork 535
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
Replace useCombinedRefs
with useRefObjectAsForwardedRef
#2204
Conversation
🦋 Changeset detectedLatest commit: be7528b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
* | ||
* **NOTE**: The `refObject` should be passed to the underlying element, NOT the `forwardedRef`. | ||
*/ | ||
export function useRefObjectAsForwardedRef<T>(forwardedRef: ForwardedRef<T>, refObject: RefObject<T>): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to suggestions for naming this. I think this name works but it could maybe be clearer. Other options I considered include:
useForwardedRefObject
useForwardedRefAsRefObject
useRefObjectAsHandle
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean ✨ I like it!
9aa7fda
to
be7528b
Compare
The
useCombinedRefs
hook only has one real use-case: combining forwarded refs with ref objects so that the value of the ref can be accessed withref.current
. Elements can only take one ref, hence we 'combine' the refs into a single ref.In #2197 I attempted to improve the hook to make it more useful. However, @mattcosta7 noted that we could completely replace this one use case with a
useImperativeHandle
call, which is absolutely correct. By wrapping that call in a simple hook and replacinguseCombinedRefs
with the new hook, we reach a number of advantages:useRef
and forwarded refs as refs. By not creating a new ref through a hook, we avoid having to pass ref objects as dependencies to effects & memosSo this PR supersedes #2197, and I feel that it's a major improvement.
Merge checklist
[ ] Added/updated testsTake a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.