React.js How to render component inside component?

前端 未结 3 667
轻奢々
轻奢々 2020-12-14 07:22

I am stuck. I have several seperate components on seperate files. If I render them in main.jsx like following:

ReactDOM.render(, doc         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 07:52

    You are right. You can use as many nested components as you want. It's one of the main concepts in react. You can access them in this.props.children. Do it like this:

    var Parent = React.createClass({
      render: function() {
        return 
    {this.props.children}
    ; } }); ReactDOM.render( , node );

    Read more here - https://facebook.github.io/react/docs/multiple-components.html

    And here - http://buildwithreact.com/article/component-children

提交回复
热议问题