TheSpicyMeatball / react-nanny

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

fix: add null check before accessing props #19

Open blabute opened 2 years ago

blabute commented 2 years ago

This corrects null reference error when a child is null/undefined (which is valid).

Closes 18.

blabute commented 2 years ago

@TheSpicyMeatball curious your thoughts on this when you get a chance!

alleksei37 commented 2 years ago

Getting the same error: TypeError: Cannot read properties of undefined (reading 'props') when one of the child nodes is undefined.

alleksei37 commented 2 years ago

Found a temporary fix/workaround - wrap the node which contains a possible undefined value in a fragment component. For example: <>{value && <p>{value}</p>}</>

blabute commented 2 years ago

Found a temporary fix/workaround - wrap the node which contains a possible undefined value in a fragment component. For example: <>{value && <p>{value}</p>}</>

Thanks for the suggestion! It definitely works but since the offending code is valid jsx, I think the repo should be updated to handle it.

blabute commented 2 years ago

@alleksei37, I shared this message on the initial issue in case you are looking for alternatives.