Skip to content

Add info to Children.toArray docs about invalid elements #1127

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

Closed
wants to merge 1 commit into from

Conversation

AEgan
Copy link

@AEgan AEgan commented Aug 16, 2018

This adds to the React.Children.toArray documentation to mention that it will filter out invalid elements.

I needed to filter out invalid child elements in an application I am working on. When searching for the best approach, I came across an old github issue facebook/react#2956, and found that the discussion led to the creation of React.Children.toArray. I didn't realize that toArray would do this, even after reading the docs for it. I thought it would be helpful to add, so I decided to open a PR. Feel free to suggest any changes to the wording, or close if you think it's not necessary.

This adds to the `React.Children.toArray` documentation to mention that
it will filter out invalid elements.

I needed to filter out invalid child elements in an application I am
working on. When searching for the best appraoch, I came across an old
github issue facebook/react#2956, and found
that the discussion led to the creation of `React.Children.toArray`. I
didn't realize that `toArray` would do this, even after reading the docs
for it, and thought it would be worthwhile to include for the next
developer looking for it.
@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

Deploy preview for reactjs ready!

Built with commit 9b680fb

https://deploy-preview-1127--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!

@kumarharsh
Copy link

+1 - Please merge this in. It takes an inordinate amount of time in parsing github issues and test cases to figure out that toArray() does indeed filter out undefined, null, etc (https://github.com/facebook/react/blob/4221565e1552425e9416035b5a4bf0ff567d18be/packages/react/src/__tests__/ReactChildren-test.js#L814)

@BartoszKlonowski
Copy link
Collaborator

Hello @AEgan, thank you for taking the time to contribute!
Would you still like to proceed with this PR? It would require to be rewritten as the sentence modified in this PR no longer exists in the latest docs. Otherwise I won't be able to review it.

@AEgan
Copy link
Author

AEgan commented Jun 25, 2024

@BartoszKlonowski I completely forgot about this!

looks like the caveat is included in the updated docs

Thanks for the reminder, I'll close out this PR

@AEgan AEgan closed this Jun 25, 2024
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.

5 participants