TheSpicyMeatball / react-nanny

Utils to manage your React Children
Other
85 stars 4 forks source link

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

Closed eugenet8k closed 2 years ago

eugenet8k commented 2 years ago

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 commented 2 years ago

@eugenet8k

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

blabute commented 2 years ago

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

blabute commented 2 years ago

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 commented 2 years ago

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

blabute commented 2 years ago

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

blabute commented 2 years ago

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.