tRPCttRPC
Powered by
rustclanR
tRPC•4y 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
signIn
loop due to the
data
data
not being there on the initial page render. But, I can't check if
!guilds.data
!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
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")
  const accessToken = trpc.auth.getAccessToken.useQuery();
  const guilds = trpc.api.getGuilds.useQuery({ accessToken: accessToken.data });

  if (!accessToken.data || !guilds.data) signIn("discord")
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

tRPC query has any type
KrishnaKKrishna / ❓-help
3y ago
Query tRPC the right way
ippoIippo / ❓-help
3y ago
trpc query help
saloodpeepoSsaloodpeepo / ❓-help
2y ago