ati
ati14mo ago

Using react-query parameters in tRPC for useQuery

Hello, the useQuery from react-query can take parameters such cacheTime, staleTime, refetchOnWindowFocus etc. , but as far as I can see we cannot give these parameters to the useQuery provided by tRPC. In this case, how can we set these values, and what are the defaults for such values? Thank you.
3 Replies
Haaxor1689
Haaxor168914mo ago
You can pass query options to useQuery hook from tRPC. Do you have a trpc query with no input? If yes then the first argument to tRPC useQuery should be undefined and options are 2nd argument.
ati
ati14mo ago
You are right, thank you! Is it a good practice to just write "undefined" in the first parameter?
Haaxor1689
Haaxor168914mo ago
Well normally with tanstack query you always write query key, async callback and options in this order but with tRPC wrapper you only pass the value there. It probably would be nice to have overload for queries with no input that only accept options as first argument but since there isn't one, passing undefined is fine. I think it even is in documentatuob like that.