fix: prevent crash when takenBy is not an array (#92)
- Add Array.isArray() checks before calling .map() on dose.takenBy - Fixes TypeError: dose.takenBy.map is not a function - Affects AppContext missedPastDoseIds calculation - Affects SchedulePage dose ID generation (3 locations) This hotfix prevents the app from crashing when dose.takenBy is null, undefined, or any non-array value.
This commit is contained in:
@@ -480,7 +480,8 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return (dose.takenBy || []).length > 0 ? dose.takenBy.map((p: string) => `${dose.id}-${p}`) : [dose.id];
|
||||
const takenByArray = Array.isArray(dose.takenBy) ? dose.takenBy : [];
|
||||
return takenByArray.length > 0 ? takenByArray.map((p: string) => `${dose.id}-${p}`) : [dose.id];
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user