Polymorphic Components
All public components support an as prop so you can change the rendered HTML element while keeping typed props.
Type signature
type AsProp<C extends React.ElementType> = {
as?: C;
};
type PolymorphicProps<C extends React.ElementType, P> = P &
AsProp<C> &
Omit<React.ComponentPropsWithRef<C>, keyof (AsProp<C> & P)>;
In practice, you usually only need:
type CommonPolymorphicProp = {
as?: React.ElementType;
};
Supported components
- Isometric
- IsometricCube
IsometricCube.Side- IsometricPlane
- IsometricGrid
Example
import { Isometric } from "isometric-react/isometric";
import { IsometricPlane } from "isometric-react/isometric-plane";
export function PolymorphicExample() {
return (
<Isometric as="main" aria-label="isometric scene">
<IsometricPlane
as="section"
id="hero-plane"
size={{ width: 8, height: 8 }}
color="#4f8bff"
/>
</Isometric>
);
}
Rendered example
Notes
- The chosen
aselement controls which native props are available (for examplehreffor links ortypefor buttons). - Component-specific props such as
size,depth, orpositionstill work the same.