asChild
A prop that tells a component to render its single child element instead of its own, merging its classes, props and behaviour onto that child.
In more detail
<Button asChild><a href="/home">Home</a></Button> renders one <a> that looks and behaves like the design system button, with no extra wrapper element. It replaces the older as prop and keeps TypeScript types simple because the child is an ordinary element. Radix UI introduced it using a Slot component.
Related terms
- slot — A place in a component's layout that the consumer fills with their own content, either through a named prop such as icon or through a Slot component.
- polymorphic component — A component that can render as different HTML elements or components, for example a Button that renders as a link.
- cloneElement — A React function that copies an element while overriding or adding props, used by Slot to merge props onto a child.
- Radix UI — An open-source library of unstyled, accessible React primitives such as Dialog, Tabs and Popover.
Taught in
- Polymorphism & Slotted Composition: The asChild Pattern — Design Systems & Component Engineering