Can I ignore undefined values from Array.map<JSX.Element> calls?
Answered
Satin Angora posted this in #help-forum
Satin AngoraOP
I have a somewhat complex component, where I have a data type that I iterate over and map properties to child components, defined as
I wonder, when I map over the
Is it better if I filter out the empty arrays before hand?
const collection: { [key in Enum]: Type[] } Because of the nature of data from server, one of the arrays may be empty (length is 0).I wonder, when I map over the
collection to create a child component and potentially encounter an empty array, can I return undefined? Or empty fragment (<></>)?Is it better if I filter out the empty arrays before hand?
1 Reply
Shy Albatross
It is better to filter first.
Answer