rustclanR
tRPC4y ago
18 replies
rustclan

TRPC waiting until the query has completed

Hey. I've just found out about TRPC and I love it. However, I was wondering if there is a way to make it so the code below my query doesn't run until the query has completed, without having to make an external function or make use of a useeffect hook in order to use await?

Is there a property of some sort which I can use to stop the page from rendering?

The code below causes an infinite signIn loop due to the data not being there on the initial page render. But, I can't check if !guilds.data, because sometimes it wont return anything, due to an invalid token. Which means there is no good way to identify when to force a signIn for the user.
  const accessToken = trpc.auth.getAccessToken.useQuery();
  const guilds = trpc.api.getGuilds.useQuery({ accessToken: accessToken.data });

  if (!accessToken.data || !guilds.data) signIn("discord")
Was this page helpful?