mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix a doc. cloneWithProps clones a ReactElement.
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
---
|
||||
id: clone-with-props
|
||||
title: Cloning Components
|
||||
title: Cloning ReactElement
|
||||
permalink: clone-with-props.html
|
||||
prev: test-utils.html
|
||||
next: update.html
|
||||
---
|
||||
|
||||
In rare situations a component may want to change the props of a component that it doesn't own (like changing the `className` of a component passed as `this.props.children`). Other times it may want to make multiple copies of a component passed to it. `cloneWithProps()` makes this possible.
|
||||
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.
|
||||
|
||||
#### `ReactComponent React.addons.cloneWithProps(ReactComponent component, object? extraProps)`
|
||||
#### `ReactElement React.addons.cloneWithProps(ReactElement element, object? extraProps)`
|
||||
|
||||
Do a shallow copy of `component` and merge any props provided by `extraProps`. The `className` and `style` props will be merged intelligently.
|
||||
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 component. If you wish to preserve the key, add it to the `extraProps` object:
|
||||
> `cloneWithProps` does not transfer `key` to the cloned element. If you wish to preserve the key, add it to the `extraProps` object:
|
||||
>
|
||||
> ```js
|
||||
> var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.key });
|
||||
> var clonedElement = cloneWithProps(originalElement, { key : originalElement.key });
|
||||
> ```
|
||||
>
|
||||
> `ref` is similarly not preserved.
|
||||
|
||||
@@ -24,7 +24,7 @@ var CHILDREN_PROP = keyOf({children: null});
|
||||
* Sometimes you want to change the props of a child passed to you. Usually
|
||||
* this is to add a CSS class.
|
||||
*
|
||||
* @param {ReactElement} child child component you'd like to clone
|
||||
* @param {ReactElement} child child element you'd like to clone
|
||||
* @param {object} props props you'd like to modify. className and style will be
|
||||
* merged automatically.
|
||||
* @return {ReactElement} a clone of child with props merged in.
|
||||
|
||||
Reference in New Issue
Block a user