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


Picture showing the output of passing children inside the component in react.js

Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Monday, August 9, 2021

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250