Cloning & Injecting Props with cloneElement
Use React.cloneElement to pass hidden props from parent to child components.
Welcome
In this lesson you will use React.cloneElement to clone a child element and inject extra props from the parent, without the child needing to know about them.
What Is cloneElement?
`React.cloneElement(element, props, ...children)` creates a new React element based on an existing one, merging the new props with the original props. The original element's type is preserved.
const clone = React.cloneElement(child, { active: true });All lessons in this course
- props.children Fundamentals
- React.Children Utilities
- Named Slots via Object Props
- Cloning & Injecting Props with cloneElement