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
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:
thank you for sharing. Here's what I changed it to:
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
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?
If it takes no input, do this
If it takes some input, like this procedure, just pass the options as a second object
okay bet this worked thank you
No worries