-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
why does React.Children.only throw? #1728
Comments
If you can provide specific use cases this would be helpful so we can look at your specific situation. In general we discourage introspecting your children and instead passing a JS object that describes the parameter in a prop. You can also use |
i creating kind of layout manager. i can't really show the code now. but i can say that in the end i found that |
React.Children.only is meant for asserting that you have a single child, not for testing whether you do – if there are expected cases where you don't, you shouldn't use that method. I can almost promise that regardless of what you do, React.Children.only will not significantly affect performance for you. |
i find my self not using
React.Children.only
because it's makes thing more complex and also it seems there are V8 performance issues (if i got it right).i've found my self writing a component that need to react different if
children
is an array or areact element
or anundefined
. and usingtry
&catch
made things more complex for this issue. it would be nice if there will be aReact.Children.isOnly
that returns aboolean
. but i seems to me that i'm missing something.The text was updated successfully, but these errors were encountered: