mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 12:43:05 +00:00
1.1 KiB
1.1 KiB
id, title, permalink, prev, next
| id | title | permalink | prev | next |
|---|---|---|---|---|
| clone-with-props | Cloning ReactElements | clone-with-props.html | test-utils.html | create-fragment.html |
Note:
cloneWithPropsis deprecated. Use React.cloneElement instead.
In rare situations, you may want to create a copy of a React element with different props from those of the original element. One example is cloning the elements passed into this.props.children and rendering them with different props:
var cloneWithProps = require('react-addons-clone-with-props');
var _makeBlue = function(element) {
return cloneWithProps(element, {style: {color: 'blue'}});
};
var Blue = React.createClass({
render: function() {
var blueChildren = React.Children.map(this.props.children, _makeBlue);
return <div>{blueChildren}</div>;
}
});
ReactDOM.render(
<Blue>
<p>This text is blue.</p>
</Blue>,
document.getElementById('container')
);
cloneWithProps does not transfer key or ref to the cloned element. className and style props are automatically merged.