Theo's Typesafe CultTTC
Theo's Typesafe Cult2y ago
3 replies
sridharK

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,
      },
    );
Was this page helpful?