-
Notifications
You must be signed in to change notification settings - Fork 47.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React.children do not take Functions as Children under consideration #11888
Comments
I think this is intentional, |
Fair enough, although it was not clear for me why my child component was not rendered. Maybe there should be some warning from React.Children that this child component was omitted? In my use case I had function as child component to render table that needed size. And it works fine like it is:
and somewere in Widget render method:
Now i wanted to add additional child component to widget:
I need to change render method in Widget to handle its children. And here I wanted to use map to do something like this:
That would be most convenient as Widget component can have diferent children depending on uscase. |
Why not do this instead? <Widget {...props} >
{(size) => (
<React.Fragment>
<Table data={prepareData(size)} />)}
<Footer {...props}/>
</React.Fragment>
)}
</Widget> Then you don't need to count the children. |
I think the above should be a better solution. |
My component can have multiple children components. They can be of different types: Strings, JSX Components and functions.
I wanted to render them using React.children.map helper function that unwraps the children opaque data structure. The problem is that children defined as functions seem to be ignored by React.children.map, React.children.count and other helper functions. See the example:
https://jsfiddle.net/bpdsraah/2/
I can access them and render directly from props.children wrapper but it is not a convenient way as one can never know for sure what type it will be.
The text was updated successfully, but these errors were encountered: