且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

React:向现有组件添加道具

更新时间:2023-12-01 08:43:04

您需要使用 React.cloneElement 例如:

You need to clone the element and add the additional props using React.cloneElement e.g:

var clonedElementWithMoreProps = React.cloneElement(
    this.mainContent, 
    { anotherMessage: "nice to meet ya!" }
);
// now render the new cloned element?