react-nanny icon indicating copy to clipboard operation
react-nanny copied to clipboard

fix: add null check before accessing props

Open blabute opened this issue 3 years ago • 5 comments

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

Closes 18.

blabute avatar Oct 24 '22 15:10 blabute

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

blabute avatar Oct 31 '22 13:10 blabute

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

alleksei37 avatar Oct 31 '22 18:10 alleksei37

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

alleksei37 avatar Oct 31 '22 18:10 alleksei37

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 avatar Oct 31 '22 21:10 blabute

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

blabute avatar Nov 01 '22 13:11 blabute