@samitouri / QOS-React-2 / commits / 48006b0e63

Add note about key prop being excluded by cloneWithProps

Whilst this is intentional behaviour (see #1274), it is not documented anywhere, so it is worth mentioning. It would also be nice if React issued a warning to console if a cloned component loses its key (as this will silently break reconciliation?)

Nick Williams committed Jul 18, 2014 at 16:14 UTC 48006b0e63c4dcc266dacd4d15542cd3a88c01c7
1 file changed +6
docs/docs/09.5-clone-with-props.md
+6
@@ -12,3 +12,9 @@ In rare situations a component may want to change the props of a component that
12 #### `ReactComponent React.addons.cloneWithProps(ReactComponent component, object? extraProps)`
13
14 Do a shallow copy of `component` and merge any props provided by `extraProps`. Props are merged in the same manner as [`transferPropsTo()`](/react/docs/component-api.html#transferpropsto), so props like `className` will be merged intelligently.
15 +
16 +**NOTE:** `cloneWithProps` does not transfer the `key` prop to the cloned component. If you wish to preserve the key, add it to the `extraProps` object:
17 +
18 +```js
19 +var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.props.key });
20 +```