I have a nested object and I have a function that should return an array of ids if they exist, or undefined if not
The problem with my code is that it returns [null] instead of null when siteIds property is null
const getContractSites = (state: AppStateType) => state.dashboard.contractAttendanceTable
export const getSites = createSelector(getContractSites, data => {
const test = data.map(attendance => {
console.log(attendance)
if (!attendance.dayShiftAttendance.siteIds) return null
return attendance.dayShiftAttendance.siteIds.map(siteId => {
return {"value": siteId}
})
})
console.log(test)
return test
})
This is a mock for my object
{
"dayShiftAttendance": {
"entityType": "SITE",
"entityId": 12792,
"entityName": "Smoke test 8th april",
"siteIds": null,
"postIds": [
36624,
36625,
36645
],
"timeShift": "Day",
"contracted": 600,
"attend": 0,
"late": 0,
"unattended": 0,
"upcoming": 0
},
"nightShiftAttendance": {
"entityType": "SITE",
"entityId": 12792,
"entityName": "Smoke test 8th april",
"siteIds": null,
"postIds": [
36624,
36625,
36645
],
"timeShift": "Night",
"contracted": 0,
"attend": 0,
"late": 0,
"unattended": 0,
"upcoming": 0
}
}