CustomLink
(createLink) and forwardRef
?
#4520
jameslawson
started this conversation in
General
Replies: 1 comment
-
Are you restricted to using React 18? In React 19, ref becomes just another prop, so you can do this:
And then the ref forwarding seems to work fine. Alternatively, you can wrap your comment in a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been following the pattern in documentation here: https://tanstack.com/router/latest/docs/framework/react/guide/custom-link#createlink-for-cross-cutting-concerns
This pattern has worked really well, it's a big improvement over the previous guidance and for me, in most cases it works great!
However, as it is
CustomLink
component is not able to foward refs which makes it incompatible with some MUI components which often expect their child components to be able to forwards ref via forwardRef (Tooltip docs, ).Example 1:
Example 2:
Is there any guidance on how to modify CustomLink in the example so that it uses forwardRef? Right now when I try to do it, no matter what I try, I can't get the TypeScript types to agree. I've been going in circles but most errors are around getting the ref types to agree (agreement between: ref parameter of forwardRef fn and ref prop of CreatedLinkComponent) Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions