Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  26] [ 6]  / answers: 1 / hits: 24484  / 6 Years ago, sun, december 23, 2018, 12:00:00

The functional components in react are better to use if there aren't any internal state to be tracked within the component.



But what I want is to access the children of the stateless components without having to extend React.Component using which i can use props.children. Is this possible ?



If so , how to do it ?


More From » reactjs

 Answers
197

We can use props.children in functional component. There is no need to use class based component for it.



const FunctionalComponent = props => {
return (
<div>
<div>I am inside functional component.</div>
{props.children}
</div>
);
};


When you will call the functional component, you can do as follows -



const NewComponent = props => {
return (
<FunctionalComponent>
<div>this is from new component.</div>
</FunctionalComponent>
);
};


Hope that answers your question.


[#52878] Monday, December 17, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
annalise

Total Points: 210
Total Questions: 94
Total Answers: 102

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
annalise questions
Mon, May 24, 21, 00:00, 3 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sat, Sep 12, 20, 00:00, 4 Years ago
Tue, Jul 28, 20, 00:00, 4 Years ago
;