APIs
cloneElement
Creates a new element using an existing element as a template. Supplied properties override matching original properties; supplied children replace existing children. Prefer explicit component props or composition when possible.
Formal Syntax & Structure
react syntaxreact
cloneElement(element, props, ...children)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| element | React element | Existing element to copy. |
| props | object | null | Overrides; null retains original props. |
| ...children | React nodes | Replacement children if supplied. |
Return Value
React element
New element; original remains unchanged.
Working Example
Example Snippetreact
import { cloneElement, createElement } from 'react';export default function App() { const original = createElement('button', {type: 'button'}, 'Reserve'); return cloneElement(original, {disabled: true});}