Polymorphism
Last updated: 2.0.0 (22/01/2024)
Polymorphism is a complex subject, and is currently a weak point of Valence's type-checking systems. Dive into this subject at your own risk.
Polymorphism allows select Valence components to take different element form on the DOM, affording the components unique attributes and functionality that are usually disallowed by React or HTML.
Valence has three primary polymorphic components:
Usage
To use polymorphism on compatible components, simply use the component
prop to change the underlying DOM component.
import { Button } from "@valence-ui/core";
function MyComponent() {
return (
<Button
component="a"
href="https://isaacshea.com"
>
Go to Isaac's website!
</Button>
)
}
When can I use this?
Every component that at some point extends the PolymorphicTextProps
, PolymorphicButtonProps
or PolymorphicLayoutProps
will support polymorphism, which generally includes:
All buttons
What is the link
component?
link
component?The component="link"
prop sets the underlying element to a react-router-dom-compatible Link
component, allowing it to interact with the React Router API.
Last updated
Was this helpful?