You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1.3 KiB

id title permalink prev next
clone-with-props ReactElementsをクローンすること docs/clone-with-props-ja-JP.html test-utils-ja-JP.html create-fragment-ja-JP.html

注意: cloneWithProps は使用不可になりました。React.cloneElementを代わりに使用してください。

元のReact要素とは異なるプロパティを持った要素のコピーを作成したいと考える稀なケースがあるかと思います。1つの例としては、以下のように、 this.props.children に渡すように要素をクローンし、異なるプロパティを持つようそれらをレンダリングするものです。

var _makeBlue = function(element) {
  return React.addons.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')
);

cloneWithPropskeyref をクローンされた要素に渡すことはありません。 classNamestyle は自動的にマージされます。