React: adding props to an existing component

后端 未结 3 1274
孤独总比滥情好
孤独总比滥情好 2021-01-31 13:57

I\'m trying to figure out how to clone an existing element with additional props.

For reference:

this.mainContent = 

        
3条回答
  •  孤街浪徒
    2021-01-31 14:37

    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?
    

提交回复
热议问题