Support for Polymorphic Paste link components #4352
Replies: 4 comments 2 replies
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. An error occurred with your deployment FUNCTION_INVOCATION_TIMEOUT sfo1::vtl7h-1751567077735-96ceb694af73 I also did a search, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
Paste's as prop only supports HTML elements (like "a", "button", "div") and does not accept custom React components such as Next.js Link. This is enforced by the type definition (keyof JSX.IntrinsicElements), so you can't currently use as={Link} on Paste components like Anchor or BreadcrumbItem. There isn't an official workaround or recommended pattern from the Paste team for integrating with Next.js Link after legacyBehavior is removed, and there are no signs of ongoing work to add this support in the repo or docs [source]. Other UI libraries (like Mantine and MUI) support a polymorphic component prop for this use case, but Paste does not at this time. For now, the best workaround is to create a custom wrapper component that composes Next.js Link and the Paste component, or to use Next.js Link directly and style its child to match Paste's design. If this is a blocker, it may be worth keeping an eye on the repo for future updates, since this is a common need in React/Next.js projects. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Hey @stern-shawn thank you for sharing this we will discuss this and get back to you in a bit. Also, Can you fill out a dependency request for this? |
Beta Was this translation helpful? Give feedback.
-
Hi @stern-shawn, this is a conversation that comes up fairly often. I think this is something that is feasible as the Link component extends the native HTML Which components exactly are you looking to have this functionality? Both |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi team!
Currently in Twilio Docs (a Next.js app), we need to follow a pattern like this to get Next.js client-side linking to work instead of having the native
<a>
tag full page reload experience:This works at the moment, but now that we've updated to Next.js 15 we're getting a warning that
legacyBehavior
will be deprecated in version 16, and to start migrating off. I tried, but Paste components don't retain the SPA link experience or fail to render without the givenhref
property.In other UI libraries that I'm used to, there's some form of API for providing a component to render in place of a given component's default output. For example:
Paste already exposes a partial version of this with the
as
prop that lets us do things like<Box as="li" />
or<Button as="a">
, and it'd be lovely to maybe extend that idea (at least on Paste components that default to rendering asa
since React apps have a tendency to need custom routing), ex:Let me know if that makes sense and is realistic, or if I'm missing something that we could more easily change now on our end 😄
Beta Was this translation helpful? Give feedback.
All reactions