Anyone here using remix? I’m having trouble trying to set an as prop to be a Link component from remix. I have an outlet that points to a Button component (the one built in). When I set as on the component, it gives me a typescript error and also crashes on remix. My work around right now is to wrap it, unfortunately if I set a link value in the editor, it becomes an a element, and then I end up wrapping an a in another a , which isn’t technically valid.
Remix is pretty new, so I doubt there is a large audience here. But, I wonder if there is something similar with just using react-router, if anyone else as run into this? Or maybe even a nextjs Link?
I figured it out, to belongs on props. Documented here for the next person that searches. Its working now, unfortunately it completely messes up the look of the component, but at least I’ve made some progress.
The wrap is closes to what I want, but I’m still stuck with an a element wrapping an a element. My workaround right now is to not add a link in the studio version, which then renders that Button component as a button
As per the shared output, using as: Link and render approach produces the same result. Which IMO is the expected behavior.
Can you please share the elements hierarchy for both NavPage and the DashboardLink component. It might helps in identifying whether it’s possible to override the parent anchor tag directly or not.
Also, just wanted to confirm that the Link you’re using is the one from remix-router (which forwards className etc. correctly)? Bizarre that the className is getting forwarded…do you happen to have a shareable example repo reproducing this?
In this case, you’re overriding Button instances, not normal a elements.
The Button component comes with its own set of styles, defined within the Button component (no styles are applied to the Button instance).
So when you say as: Link, it no longer renders a Button (along with its styles), and renders a plain Link.
If you instead applied as: Link to a styled a tag (or any other styled element), you should see those styles continue to get passed into the Link as className.
But actually - a better thing to do in this case is you could globally wrap all your Buttons inside a Link using component substitution.
But essentially, I think you should be able to change your Button.tsx to something like this (this probably isn’t quite right but something like this, will need to look it up later):
I see, it is replacing the component entirely when you use as prop. I’ve been using Chakra which still passes through the styles on an as prop, so my expectations were off.