Cloning ReactElements

Note: cloneWithProps is 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 =, _makeBlue);
    return <div>{blueChildren}</div>;

    <p>This text is blue.</p>

cloneWithProps does not transfer key or ref to the cloned element. className and style props are automatically merged.

results matching ""

    No results matching ""