I am trying to work on a fairly basic app that calls Dynatrace API for entities and then want to parse out the entityId and build an array of entities. I think that this might be specific to Typescript and not sure how to solve it. I know that I am getting an result array of objects, but when trying to use map, is telling me that entities is possibly undefined. Any help would be appreciated.
const [entitiesArray, setEntitiesArray] = useState<any[]>([]);
useEffect(() => {
monitoredEntitiesClient.getEntities(
{
entitySelector: 'type("HOST"),tag("OpenShift_App_Nodes")',
from: 'now-1y/M',
pageSize: 900
})
.then(response => {
// console.log('response:', response)
const entities = response?.entities
console.log('entities:', entities)
setEntitiesArray(entities.map(entity => entity?.entityId))
})
}, []);