我正在尝试找出如何使用附加道具克隆现有元素。
以供参考:
this.mainContent = <Hello message="Hello world!" />
我尝试做类似的事情
React.createElement(this.mainContent, Object.assign({},
this.mainContent.props, { anotherMessage: "nice to meet ya!" }));
但它不起作用。
我将如何实现这个目标?
您需要克隆元素并使用添加附加道具React.cloneElement https://facebook.github.io/react/docs/top-level-api.html#react.cloneelement e.g:
const ClonedElementWithMoreProps = React.cloneElement(
this.mainContent,
{ anotherMessage: "nice to meet ya!" }
);
// now render the new cloned element?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)