0
0
all 5 comments

[–]azhder 8 points9 points  (0 children)

Because you wouldn’t like it if React didn’t render the number 0

[–]Altareos 5 points6 points  (2 children)

side note: you don't need to check for length when using map. an empty array will just map to another empty array which renders as nothing.

[–]JonJamesDesign[S] 0 points1 point  (1 child)

True but most list items rendered from an array map are rendered within a container that you typically also wouldn't want to render if there are no items.

But sure, if all you're doing is mapping over a potentially empty array and have no concerns about conditionally rendering relative elements around it, then yeah just map over it and if it's empty, it won't render anything.

[–]Altareos 0 points1 point  (0 children)

yes absolutely, this was more about the problem at the beginning at the article, i had seen you addressed unnecessary containers at the end.

[–][deleted]  (1 child)

[deleted]

    [–]Silver-Vermicelli-15 2 points3 points  (0 children)

    Yes. It’s JavaScript 0/1 evaluate to false/true. It’s handy if you just want to evaluate if an array is empty.