I was learning React and came across props.children
and asked myself why it was created and what problems it came to solve. After some research, I understood that props.children
is best to be used when we want to pass JSX to a certain component. Then, I asked myself again if props.children
is used to pass JSX as props to a component then isn't it also OK to pass props like this: myProp={<div><SomeComponent>Some String</div>}
?
Asked
Active
Viewed 45 times
0

jonrsharpe
- 115,751
- 26
- 228
- 437

Mir
- 75
- 8
-
Does this answer your question? [What is {this.props.children} and when you should use it?](https://stackoverflow.com/questions/49706823/what-is-this-props-children-and-when-you-should-use-it) – norbitrial Mar 25 '20 at 18:01
-
@norbitrial, yeah I read about it could not get EXACT answer. thus I decided to ask. – Mir Mar 25 '20 at 18:07
-
The children prop is the ReactNode that is wrapped by your component. It's more convenient to use children than to have to create a new prop and pass JSX to that, and it allows a comparable approach to building components. – JMadelaine Mar 25 '20 at 18:38