Skip to content
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

There is a crash if one of the children element is null #18

Closed
eugenet8k opened this issue Sep 27, 2022 · 6 comments
Closed

There is a crash if one of the children element is null #18

eugenet8k opened this issue Sep 27, 2022 · 6 comments

Comments

@eugenet8k
Copy link

If React markup has a child under the condition

<div>
      <div>Header</div>
      {description && <p>{description}</p>}
</div>

the result children will be [element, null] and that will crash the lib.

@TheSpicyMeatball
Copy link
Owner

@eugenet8k

Is there a specific function in the lib that you can point me to that has this issue?

@blabute
Copy link

blabute commented Oct 24, 2022

Hello! I came to this issue since I ran into it as well. I was using the getChildByTypeDeep function.

@blabute
Copy link

blabute commented Oct 24, 2022

FWIW, if I remove the filter part of this line from the tests and add a test case like { type: 'div', props: { children: [null, {type: 'div'}] } }, to the children in src/getChildByType/index.deep.test.js, I get this error as well.

Can you explain why https://github.com/TheSpicyMeatball/react-nanny/blob/main/src/getChildByType/index.deep.test.js#L31 is added to the tests and not something we handle in the src?

@blabute
Copy link

blabute commented Oct 24, 2022

I took a stab at correcting this here. Please let me know what you think!

@blabute
Copy link

blabute commented Oct 31, 2022

@TheSpicyMeatball not sure if you got notified of this since it's a closed issue, thanks!

@blabute
Copy link

blabute commented Nov 1, 2022

In case anyone else stumbles upon this issue, our team has decided to use react-children-utilities instead. It supports our needs, has more stars, has more downloads, is smaller, and supports React 15 - 18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants