-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Improved the documentation for React.Children.only #118
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
Improved the documentation for React.Children.only #118
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Deploy preview ready! Built with commit ea6d90e |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
content/docs/reference-react.md
Outdated
|
||
> Note: | ||
> | ||
>`React.Children.only()` does not accept as argument a return value from [`React.Children.map()`](#reactchildrenmap) because the return of the latest is not a React element. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about
Verifies that
children
has only one child (a React element) and returns it. Otherwise this method throws.
Note:
React.Children.only()
does not accept the return value ofReact.Children.map()
because it is an array rather than a React element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. I will make the change right now.
…ntation simpler to understand. Fixes #87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig it 👍
Sync with reactjs.org @ 21ca8ed
Fixes #87
Changed the documentation for
React.Children.only()
to make its implementation simpler to understand.Since a lot of issues related with this method are connected to the fact that one cannot use a return value from
React.Children.map()
, added a note to explain why map does not return values that can be accessed used byReact.Children.only()
. This can easily be tested in a simple implementation by console logging the return value of map toReact.isValidElement()
, which is what the children.only method checks for itself. This will return false. The structure of the children should still be that of an object for the method to accept it and return it.I think this note is necessary but I am unsure on the grammatical structure to make it understandable. If you could please check and maybe suggest a way for it to make sense to future readers of the docs.