React.js How to render component inside component?

前端 未结 3 664
轻奢々
轻奢々 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:41

    Here Car component is inside the another component i.e Garage components. When Garage component in rendering Car component is also renders. Same concept as like one function inside another function.

    class Car extends React.Component {
      render() {
        return 

    I am a Car!

    ; } } class Garage extends React.Component { render() { return (

    Who lives in my Garage?

    ); } } ReactDOM.render(, document.getElementById('root'));

提交回复
热议问题