-
Notifications
You must be signed in to change notification settings - Fork 47k
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.onlyChild throws on text child #1104
Comments
I don't understand the use case of this like this either, making it public at this point may be a mistake? |
|
@spicyj @sebmarkbage is this still the case now that we wrapped this? |
Nothing here has changed. If you call |
It's not an element. It's a ReactNode. Might be possible to have an isValidNode but I thought we have a propType for that already. |
Hey just wanted to mention that I encountered this problem on a wrapper component. It looks like:
I can't call I can't either remove the check since it raises So the solution I found was
Not sure it helps, just wanted to explain my usecase so that you can think of it when taking any action |
My understanding was that whatever's in props.children is a child or array of children. Just like If nothing else, the name and docs are a bit vague considering how specific the implementation is, and the definition of 'child' is ambiguous. I've never used it, but there's nothing indicating that a string or number isn't a valid value, so I'd assume they were and eventually end up at this issue in a google search while debugging the problem. |
The error message for this is: |
I actually already improved this message in 15.3.1: https://github.com/facebook/react/blob/v15.3.1/src/isomorphic/children/onlyChild.js#L34. |
Cool - that's a bit more specific. As a next step, it would be nice to actually detect and message what exactly is invalid for the most common cases. |
Text child is a string so
isValidComponent
fails. Would it make sense for it to accept a string? Frankly I'm confused by this API...The text was updated successfully, but these errors were encountered: