DEV Community

Discussion on: Reusing CSS With Styled Components

mglavall profile image

Styled components has a property for this kind of use cases:

If you want to keep all the styling you've applied to a component but just switch out what's being ultimately rendered (be it a different HTML tag or a different custom component), you can use the "as" prop to do this at runtime.

stephencweiss profile image
Stephen Charles Weiss Author

Good point! When I wrote this I hadn't yet found polymorphic components. When I did a few weeks later, I wrote about them as well: :)

(One point: I have had trouble with polymorphic components in my typescript app. Haven't dug into it too deeply yet, but just something to keep in mind)