Skip to content

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

Merged
merged 1 commit into from
Oct 10, 2017
Merged

Improved the documentation for React.Children.only #118

merged 1 commit into from
Oct 10, 2017

Conversation

renatoselenica
Copy link
Contributor

@renatoselenica renatoselenica commented Oct 10, 2017

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 by React.Children.only(). This can easily be tested in a simple implementation by console logging the return value of map to React.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.

@facebook-github-bot
Copy link
Collaborator

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!

@reactjs-bot
Copy link

reactjs-bot commented Oct 10, 2017

Deploy preview ready!

Built with commit ea6d90e

https://deploy-preview-118--reactjs.netlify.com

@facebook-github-bot
Copy link
Collaborator

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!


> 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.
Copy link
Contributor

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 of React.Children.map() because it is an array rather than a React element.

Copy link
Contributor Author

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.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it 👍

@bvaughn bvaughn merged commit c6076da into reactjs:master Oct 10, 2017
@renatoselenica renatoselenica deleted the children-only-documentation branch October 11, 2017 06:37
jhonmike pushed a commit to jhonmike/reactjs.org that referenced this pull request Jul 1, 2020
BetterZxx pushed a commit to BetterZxx/react.dev that referenced this pull request Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants