polymorphic component

A component that can render as different HTML elements or components, for example a Button that renders as a link.

In more detail

The older approach is an as prop, such as <Button as="a">, which makes TypeScript types large and slow and can break ref forwarding. The asChild pattern achieves the same goal by letting the consumer pass the element to render.

Example

function Box({ as: Tag = "div", children }) { return <Tag>{children}</Tag>; }

Related terms

Taught in

References