mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-25 23:05:23 +00:00
1.0 KiB
1.0 KiB
id, title, permalink, prev, next
| id | title | permalink | prev | next |
|---|---|---|---|---|
| clone-with-props | Cloning Components | clone-with-props.html | test-utils.html | 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.
ReactComponent React.addons.cloneWithProps(ReactComponent component, object? extraProps)
Do a shallow copy of component and merge any props provided by extraProps. Props are merged in the same manner as transferPropsTo(), so props like className will be merged intelligently.
Note:
cloneWithPropsdoes not transfer thekeyprop to the cloned component. If you wish to preserve the key, add it to theextraPropsobject:var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.props.key });