I have a code in place which looks like this -
mapFn={response => (response.data && response.data.map(secret => ({
label: secret.secretName,
value: secret.id
})))}
I need to add one more additional object to response.data before it maps and sets it tp mapFn. So I tried something like -
mapFn={response => (response.data &&
response.data.append({label: "Select Vault ID", value: "value"})
&& response.data.map(secret => ({
label: secret.secretName,
value: secret.id
})))}
But I am getting an error as -
TS2339: Property 'append' does not exist on type 'SecretSummary[]
response.datais an array. Arrays don't have an.appendmethod. They do have a.pushmethod, but it returns a number, rather than the array (and it mutates, which is forbidden in React). Another issue is that the object you're adding has alabelandvalueproperty - which sounds like something that should be added after mapping, not before mapping.Spread the mapped into a new array, and list the object you want to add at the end.
(If you wanted to add the object before mapping, you'd probably want to use the
secretNameandidproperties when defining the object instead, because otherwise calling the.mapcallback with the object wouldn't make sense.)