Render childrens in React component

How to render childrens in react component


You may not that with in the opening and closing tags of a component there can be other tag like div can contain table, list etc. By default React component hide all the components within.

So how to render the children ?

functional component

In the functional component at the end of the render section add

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

)

Class component

In the class component we have to use the this for accessing the props

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

)

Author: Manoj

Developer and a self-learner, love to work with Reactjs, Angular, Node, Python and C#.Net

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.