-
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.map doesn't work with "Function as Child" Components #7806
Comments
Functions are not valid React Elements, so they're discarded by |
@syranide @sebmarkbage Somehow this feels like it breaks the abstraction. Children are anything within the body of the JSX tag. If I do |
|
@syranide what about SFCs, which are also simple functions? |
@syranide @sebmarkbage That makes sense. If I use functions as children, I'll just handle their opaque data structure myself. Thanks for clarifying! @yaycmyk SFCs are still represented as React Elements with the |
If I create a component that accepts functions as its children, I'm not able to use
React.Children.map
to map through them (it returns nothing). I instead have to just useprops.children.map()
- but that throws an error if there's only one child.Here's a JS Bin illustrating the issue: http://jsbin.com/fufaga/edit?js,output
I'm not sure if this is a bug, or intended functionality, or if it's just not recommended to build components this way.
(The JS Bin example is using React 15.1, but I'm experiencing this on 15.3.1 as well.)
The text was updated successfully, but these errors were encountered: