How to use useQuery...?
Uber noob question here, I seem to have a misunderstanding of useQuery. Here is all im trying to do - use it to return an array from my database, console log the data.
Here is my component, when it loads it doesn't log anything (because getAllCars.data hasn't resolved yet?), as if I need to await the data (what is the pattern for this in TRPC?). If I wasn't using TRPC, I would have the cars data set to a state so I can put the loop inside a useEffect with cars state as a dependancy, however I understand the TRPC patterns are different. Looking at the useQuery docs, the useQuery example doesn't help. The data just seems to be there?
Anyway the solution is presumably. very simple, hoping someone can point me in the right direction
8 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
useQuery is a hook, not a function and it itself already returns the data
Ugh, for some reason I thought only state could be used in a dep array. Like a thought, simple solution. Thankyou so much!
wait i misread the code fuck sorry
yea just simple dep stuff
No problem! Appreciate the response
i do wonder if the useEffect is necessary at all though
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
It's not
data is state