0 votes
in ReactJS by
What is children prop?

2 Answers

0 votes
by

Children is a prop (this.props.children) that allow you to pass components as data to other components, just like any other prop you use. Component tree put between component's opening and closing tag will be passed to that component as children prop.

There are a number of methods available in the React API to work with this prop. These include React.Children.map, React.Children.forEach, React.Children.count, React.Children.only, React.Children.toArray.

A simple usage of children prop looks as below,

const MyDiv = React.createClass({

  render: function() {

    return <div>{this.props.children}</div>

  }

})

ReactDOM.render(

  <MyDiv>

    <span>{'Hello'}</span>

    <span>{'World'}</span>

  </MyDiv>,

  node

)

0 votes
by

Children props are used to pass component to other components as properties. You can access it by using

{props.children}

Related questions

0 votes
asked Jan 31, 2021 in ReactJS by Robindeniel
+1 vote
asked May 29, 2020 in ReactJS by anonymous
...