cloneElement
A React function that copies an element while overriding or adding props, used by Slot to merge props onto a child.
In more detail
React.cloneElement(child, { className: merged }) returns a new element with the merged class. The React team now lists it as uncommon because it makes data flow harder to follow, but it remains the usual way to implement asChild.
Related terms
- 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.
- 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.
Taught in
- Polymorphism & Slotted Composition: The asChild Pattern — Design Systems & Component Engineering