我试图弄清楚如何使用其他道具克隆现有元素。
以供参考:
this.mainContent = <Hello message="Hello world!" />
我试图做类似的事情
React.createElement(this.mainContent, Object.assign({}, this.mainContent.props, { anotherMessage: "nice to meet ya!" }));
但它不起作用。
我将如何完成?
您需要使用以下命令克隆元素并添加其他道具React.cloneElement:
React.cloneElement
var clonedElementWithMoreProps = React.cloneElement( this.mainContent, { anotherMessage: "nice to meet ya!" } ); // now render the new cloned element?