From 48006b0e63c4dcc266dacd4d15542cd3a88c01c7 Mon Sep 17 00:00:00 2001 From: Nick Williams Date: Fri, 18 Jul 2014 16:14:55 +0100 Subject: [PATCH 1/2] 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?) --- docs/docs/09.5-clone-with-props.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/docs/09.5-clone-with-props.md b/docs/docs/09.5-clone-with-props.md index 0d466adf4a..d6a4bc0ab7 100644 --- a/docs/docs/09.5-clone-with-props.md +++ b/docs/docs/09.5-clone-with-props.md @@ -12,3 +12,9 @@ In rare situations a component may want to change the props of a component that #### `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()`](/react/docs/component-api.html#transferpropsto), so props like `className` will be merged intelligently. + +**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: + +```js +var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.props.key }); +``` From ee325eb5d5fbb91de7e6bbd7cfab4e7d30287821 Mon Sep 17 00:00:00 2001 From: WickyNilliams Date: Mon, 21 Jul 2014 17:11:40 +0100 Subject: [PATCH 2/2] follow docs convention for notes --- docs/docs/09.5-clone-with-props.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/docs/09.5-clone-with-props.md b/docs/docs/09.5-clone-with-props.md index d6a4bc0ab7..aa96aff08e 100644 --- a/docs/docs/09.5-clone-with-props.md +++ b/docs/docs/09.5-clone-with-props.md @@ -13,8 +13,9 @@ In rare situations a component may want to change the props of a component that 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. -**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: - -```js -var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.props.key }); -``` +> 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: +> ```js +> var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.props.key }); +> ```