Children is a prop (
this.prop.children
) that lets you pass components as data to other components, just like any other prop you use. The component tree placed between a component's opening and closing tags is passed to that component as the children
prop.
The React API provides several methods for working with this object. They include
React.Children.map
, React.Children.forEach
, React.Children.count
, React.Children.only
, React.Children.toArray
. A simple use of the children prop looks like the following,
const MyDiv = React.createClass({
render: function() {
return <div>{this.props.children}</div>
}
})
ReactDOM.render(
<MyDiv>
<span>{'Hello'}</span>
<span>{'World'}</span>
</MyDiv>,
node
)
Comments