Error: Invalid hook call. (useQuery inside useEffect)
Hi, I'm using clerk + convex in Expo.
I'm trying to load user data once the user is set on sign-in from clerk's useUser hook. To do this, I have placed the useQuery hook inside useEffect, which is causing this error. I have also tried putting the useQuery call inside useCallback - that did not throw an error but did not work as intended. Could anyone please suggest me a proper way to achieve this? Thanks.
code:
error:


2 Replies
You can't nest hooks, they have to be called directly from the top scope of a component (or another hook).
For this, though, you can avoid the hassle and use the
skip
arg: https://docs.convex.dev/client/react#skipping-queriesConvex React | Convex Developer Hub
Convex React is the client library enabling your React application to interact
Passing the string "skip" as the sole query arg keeps the query from executing.