Next.js Discord

Discord Forum

Can I ignore undefined values from Array.map<JSX.Element> calls?

Answered
Satin Angora posted this in #help-forum
Open in Discord
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
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?
Answered by Shy Albatross
It is better to filter first.
View full answer

1 Reply

Shy Albatross
It is better to filter first.
Answer