const tableData = props.item && props.item.details && props.item.details.clients.reduce((acc, client) => acc.concat( ...client.errorConfigurations.map(config => ({ errorMessage: config.error.message, errorLevel: config.error.level, usedIn: client.client.name })) ) );
is missing the initial value for reduce, such as a []. And like @samuraiseoul mentioned, this is a case for a flatMap.
reduce
[]
const tableData = props.item?.details?.clients.flatMap( ({ client, errorConfigurations }) => errorConfigurations.map(({ error }) => ({ errorMessage: error.message, errorLevel: error.level, usedIn: client.name })) )
If you don't have your own flatMap yet, store bought is fine:
flatMap
const flatMap = <T, R>(fn: (x: T) => R[], arr: T[]) => { const out: T[] = [] const { push } = Array.prototype for (const x of arr) push.apply(out, fn(x)) }
JK, don't use this one, it's probably not very good.
Thanks for pointing the missing initializer, fixing!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
is missing the initial value for
reduce
, such as a[]
.And like @samuraiseoul mentioned, this is a case for a flatMap.
If you don't have your own
flatMap
yet, store bought is fine:JK, don't use this one, it's probably not very good.
Thanks for pointing the missing initializer, fixing!