TRPC UseQuery

How can I have a trpc useQuery hook only be called if there is an active logged in session? I understand that you can't use hooks inside conditional statements, and that's why I'm getting the following error. Unhandled Runtime Error Error: Rendered more hooks than during the previous render. Image If I put the useQuery outside of the if statement, the code works as expected but I'm not sure if that's a good practice to call protected routes when no one is logged in. Image
8 Replies
Vincent Udén
Vincent Udén2y ago
Disabling/Pausing Queries | TanStack Query Docs
If you ever want to disable a query from automatically running, you can use the enabled = false option. When enabled is false:
kirk
kirkOP2y ago
thank you for sharing. Here's what I changed it to:
kirk
kirkOP2y ago
I am getting the following error tho: Argument of type '{ enabled: boolean; }' is not assignable to parameter of type 'void'.ts(2345) Is there something I need to change in my configs or something
Vincent Udén
Vincent Udén2y ago
Haven't used tRPC v10 a lot yet, gimmie a sec I'll see if I can figure out how to pass options to tanstack query through trpc Does subscriptionStatus take no input? Or does it take an empty object?
Vincent Udén
Vincent Udén2y ago
If it takes no input, do this
Vincent Udén
Vincent Udén2y ago
If it takes some input, like this procedure, just pass the options as a second object
kirk
kirkOP2y ago
okay bet this worked thank you
Vincent Udén
Vincent Udén2y ago
No worries

Did you find this page helpful?