is there a way to create a reusable <Link /> component?
I'd like to create a reusable link component with styles but have access to the
to prop so i have autocompletion for routes14 Replies
flat-fuchsiaOP•2y ago
got it!
relaxed-coral•2y ago
I do it like this, not only
to props but params etc has typesafety too.
flat-fuchsiaOP•2y ago
thank you so much @JfrAziz
exotic-emerald•2y ago
there now is also the experimental function
createLink
see https://github.com/TanStack/router/commit/c2fbb56b251d10f2c2832916ea60a779c079ae24
not yet documented but you could try itforeign-sapphire•2y ago
Is there way to achieve previous versions Link functionality @Manuel Schiller
I am not sure whether createlink is good way to create custom link as most of UI libraries supports as or custom component prop passing Link component directly looks better to me but it's broken on latest version for now I have to revert to old versions
exotic-emerald•2y ago
@Bhunter can you please comment here? https://discord.com/channels/719702312431386674/1214176201216630784
let us know why this does not work for your use case
relaxed-coral•2y ago
@Manuel Schiller i get this error use createLink or am I wrong?
exotic-emerald•2y ago
@Tanner Linsley is this something
createLinkshould support?continuing-cyan•2y ago
We are using forwardRef under the hood, so I'll need more details...
exotic-emerald•2y ago
I think the example above is all that is needed here ?
continuing-cyan•2y ago
ahhhhhhhh
Yeah, let me fix this
Actually
I think the consumer needs to also forward ref
Try this:
And let me know if typescript dies
flat-fuchsiaOP•2y ago
oo would love a page on the canonical way to create a reusable link in tanstack router! im also down to contribute!
flat-fuchsia•2y ago
@char and others, any progress on docs for this feature? Besides just reusable Link component I am looking into creating reusable component that is optionally a link. For this reason I have something like:
But in the
<Link /> component I have the error of:
exotic-emerald•2y ago
did you try
createLink?