-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Children forEach filters functions #9821
Comments
🤔 @neytema I am not able to reproduce this. What browser are you using? |
Hey @neytema, I did some experimenting and it appears that all React.Chilrden utilities filter down to just component children. It's not totally clear from the React.Children docs if that's the intended behavior, but I think it might be. But I'm no React expert so I'm not sure. It looks like you could just use the "children" prop as an array normally if you'd like to iterate through the functions, though. |
@ahlusar1989 nodejs v6.10.3 @frankalbenesius I am concerned about inconsistency.. If you'd pass an object type child Object example: const element = <div>{{}}</div>;
React.Children.toArray(element.props.children);
// throws 'Objects are not valid as a React child (found: object with keys {}).' And you can't simply use children as array because it is not always an array or not a flat one. |
@neytema I understand. Referencing the above example, you would need to pass a string type or React component(created by |
Landed here because I couldn't get functions as children to work with |
React v15.5.4
Unexpected behaviour of
React.Children.forEach
– silently filters functions.Current behavior:
Expected behavior:
Children.forEach should throw Invariant error then function type child is met.
or
Children.forEach shouldn't filter function type children.
The text was updated successfully, but these errors were encountered: