sridharK
sridharK
Explore posts from servers
TTCTheo's Typesafe Cult
Created by sridharK on 5/23/2024 in #questions
T3 trpc depdent query is failing ?
I have this code , my third question getQuestion useQuery is failing not sure why, I read about from online but adding enabled did not solve it, the error is TypeError: Cannot read properties of undefined (reading 'length'), can anyone help me on this ?
const event = api.slido.getSlido.useQuery({ id: eventId });
const poll = api.poll.getAll.useQuery(
{ slidoId: eventId },
{ enabled: !!event },
);

const { data: eventData, isLoading } = event;
const { data: pollData } = poll;
const currentPoll = pollData?.find((item) => item.slidoId === eventId);
const pollId = currentPoll?.id;

console.log({ currentPoll }, currentPoll?.id);

const question =
currentPoll?.id &&
api.question.getQuestions.useQuery(
{
pollId: currentPoll.id,
},
{
enabled: !!pollId,
},
);
const event = api.slido.getSlido.useQuery({ id: eventId });
const poll = api.poll.getAll.useQuery(
{ slidoId: eventId },
{ enabled: !!event },
);

const { data: eventData, isLoading } = event;
const { data: pollData } = poll;
const currentPoll = pollData?.find((item) => item.slidoId === eventId);
const pollId = currentPoll?.id;

console.log({ currentPoll }, currentPoll?.id);

const question =
currentPoll?.id &&
api.question.getQuestions.useQuery(
{
pollId: currentPoll.id,
},
{
enabled: !!pollId,
},
);
4 replies