Articles → REACT.JS → Pass Children Inside The Component In React.Js
Pass Children Inside The Component In React.Js
Example
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class ChildComponent extends React.Component {
render() {
return (
<div>
{this.props.children}
This is the child component
</div>
);
}
}
class ParentComponent extends React.Component {
render() {
return (
<div><ChildComponent><h4>Title</h4></ChildComponent></div>
);
}
}
ReactDOM.render(<ParentComponent />, document.getElementById('root'));
Output
Click to Enlarge