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.1 KiB

id title permalink prev next
clone-with-props-it-IT Clonare ReactElements clone-with-props-it-IT.html test-utils-it-IT.html create-fragment-it-IT.html

Nota: cloneWithProps è deprecato. Usa React.cloneElement al suo posto.

In rare condizioni, potresti voler creare una copia di un elemento React con proprietà diverse da quelle dell'elemento originale. Un esempio è clonare gli elementi passati come this.props.children ed effettuarne il rendering con proprietà diverse:

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>Questo testo è blu.</p>
  </Blue>,
  document.getElementById('container')
);

cloneWithProps non trasferisce gli attributi key o ref agli elementi clonati. Le proprietà className e style sono automaticamente riunite.