mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
942 B
942 B
id, title, permalink, prev, next
| id | title | permalink | prev | next |
|---|---|---|---|---|
| clone-with-props | Cloning ReactElement | clone-with-props.html | test-utils.html | create-fragment.html |
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.
ReactElement React.addons.cloneWithProps(ReactElement element, object? extraProps)
Do a shallow copy of element and merge any props provided by extraProps. The className and style props will be merged intelligently.
Note:
cloneWithPropsdoes not transferkeyto the cloned element. If you wish to preserve the key, add it to theextraPropsobject:var clonedElement = cloneWithProps(originalElement, { key : originalElement.key });
refis similarly not preserved.