Skip to content

Commit

Permalink
Fix trying to access undefined's property
Browse files Browse the repository at this point in the history
  • Loading branch information
jakdan99 committed Nov 4, 2024
1 parent 98b08be commit 9fcfbed
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/pages/Participant/ParticipantDataCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Stack,
Typography,
} from "@mui/material";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useParams } from "react-router-dom";
import carpCommon from "@cachet/carp-common";
import { useStudyDetails } from "@Utils/queries/studies";
Expand Down Expand Up @@ -59,13 +59,20 @@ const ParticipantDataCard = () => {
} = useGetParticipantData(deploymentId);

const [participant, setParticipant] = useState<ParticipantData | null>(null);
const initalValues =
(participantData?.roles as any as Array<any>).length !== 0
? (participantData?.roles as any as Array<any>)
.filter((v) => v)
.map((v) => v.data.values.toArray().filter((value) => value))
.flat()
: participantData?.common.values.toArray().filter((v) => v);
const initalValues = useMemo(() => {
if (
participantData?.roles &&
(participantData?.roles as any as Array<any>).length !== 0
)
return (participantData?.roles as any as Array<any>)
.filter((v) => v)
.map((v) => v.data.values.toArray().filter((value) => value))
.flat();
if (participantData?.common.values)
return participantData?.common.values.toArray().filter((v) => v);
return null;
}, [participantData]);

useEffect(() => {
if (participantGroupStatus) {
setParticipant(
Expand Down

0 comments on commit 9fcfbed

Please sign in to comment.