avoid rendering more hooks: running trpc query based on supabase session's user
i have a router
workspace
with query getWorkspace
that takes the current supabase session's user's UUID id and returns details of the workspace they're a member of
but on my /pages/today.tsx
where i need that workspace info, it's throwing Unhandled Runtime Error
Error: Rendered more hooks than during the previous render
22 Replies
Instead, set disabled to true or false
Don't do hooks optionally, never.
sorry, what should i be disabling?
useQuery hook takes options, one of those are called
disabled
, takes in true or false
Oh wait no it's called enabled
lolaight, i modified it to this but since supabase's type im importing for
User
can also be undefined, it's giving me that message. which is why i had the condition before. is there a better way to handle this?
Idk how Supabase's promises work but I'm assuming this would work
Or asserting that
typeof user.id === string
should work toohmm that won't get around the typeerror, since the user state is undefined until the
getUser
runs in useEffect
NOT equal undefined
The not is important
whoops i forgot to change it back
What if you did this
enabled: user && "id" in user
same issue, does order matter for useQuery's args or something?
nvm def not order
I guess you can just do optional chaining
how would i go back to that and avoid the error we started with 😦
Unhandled Runtime Error
Error: Rendered more hooks than during the previous render.
Just do
user?.id
?oh i misunderstood, let me try that
that means i'll have to allow
user_id: z.union([z.string(), z.undefined()]),
in the trpc router's input rightDon't think so