Compositions vs Inheritence (React)

Estimated reading time: 1 minute

what is Compositions

  • It’s as like a props . Basically it is components props .
//Test.js
Class Test extends Component {
  constructor(props){
    super(props)
  }
  render(
    <div>
      {this.props.top}
      {this.props.middle}
      {this.props.bottom}
    </div>
  )
}
//Body.js
Class Test extends Component {
  render(
    <Test top={<TopComponent/>}
          middle={<MiddleComponent/>}
          bottom={<BottomComponent/>}
    />
  )
}
react, react.js, js