You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
942 B

11 years ago
---
id: clone-with-props
title: Cloning ReactElement
11 years ago
permalink: clone-with-props.html
prev: test-utils.html
next: create-fragment.html
11 years ago
---
In rare situations a element may want to change the props of a element that it doesn't own (like changing the `className` of a element passed as `this.props.children`). Other times it may want to make multiple copies of a element passed to it. `cloneWithProps()` makes this possible.
11 years ago
#### `ReactElement React.addons.cloneWithProps(ReactElement element, object? extraProps)`
11 years ago
Do a shallow copy of `element` and merge any props provided by `extraProps`. The `className` and `style` props will be merged intelligently.
> Note:
>
> `cloneWithProps` does not transfer `key` to the cloned element. If you wish to preserve the key, add it to the `extraProps` object:
>
> ```js
> var clonedElement = cloneWithProps(originalElement, { key : originalElement.key });
> ```
>
> `ref` is similarly not preserved.