You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a table cell component that will specially handle the case where it's given a single number, and from looking at the documentation and API, I'm unclear on how to do this:
"Multiple Components" and "Top-level API" say that this.props.children is "opaque" and suggest that the React.Children APIs should be used to preserve this.props.children's encapsulation.
"Type of the Children props" gives full details on how this.props.children is implemented and suggests that React.Children is provided simply as a convenience.
My questions, or suggestions for improvements to the docs:
Is this.props.children supposed to be opaque? If so, "Type of the children props" should be updated.
Or is it supposed to be public? If so, "Multiple Components" and "Top-level API" should be updated.
Can the documentation for React.Children.only be updated to clarify that it requires a valid React element and possibly to explain the use case for this requirement? (See comments on React.Children.onlyChild throws on text child #1104 for some of the confusion caused by the current documentation.)* What's the official or recommended way to get at the only "anything renderable" child, as opposed to the only "valid React element" child?
I'm writing a table cell component that will specially handle the case where it's given a single number, and from looking at the documentation and API, I'm unclear on how to do this:
this.props.children
is "opaque" and suggest that theReact.Children
APIs should be used to preservethis.props.children
's encapsulation.this.props.children
is implemented and suggests thatReact.Children
is provided simply as a convenience.React.Children.only
say thatonly
gets the single child, but in reality, it gets the single child as long as that child is a React element. (React 15.3.1 at least improves the error message in this case.)My questions, or suggestions for improvements to the docs:
this.props.children
supposed to be opaque? If so, "Type of the children props" should be updated.React.Children.only
be updated to clarify that it requires a valid React element and possibly to explain the use case for this requirement? (See comments on React.Children.onlyChild throws on text child #1104 for some of the confusion caused by the current documentation.)* What's the official or recommended way to get at the only "anything renderable" child, as opposed to the only "valid React element" child?React.Children.only
to allow for string and number nodes was closed as won't fix (React.Children.onlyChild throws on text child #1104)this.props.children
directly goes against the docs' statement that it should be opaque.React.Children.map
orReact.Children.forEach
seems like overkill.If
this.props.children
is supposed to be opaque, then would a newReact.Children.onlyNode
function be a useful solution?The text was updated successfully, but these errors were encountered: