Prevent trpc refetching
Does anyone have an idea how I prevent trpc refetching, current I have following queries in a page:
Which keeps refetching if I focus on the application.
I went through the docs https://tanstack.com/query/v4/docs/react/guides/window-focus-refetching
And tried:
But I get this:
Window Focus Refetching | TanStack Query Docs
If a user leaves your application and returns to stale data, React Query automatically requests fresh data for you in the background. You can disable this globally or per-query using the refetchOnWindowFocus option:
Disabling Globally
15 Replies
you may need to put that as the second parameter and not the first
useQuery() | tRPC
The hooks provided by @trpc/react-query are a thin wrapper around @tanstack/react-query. For in-depth information about options and usage patterns, refer to their docs on queries.
@needmorewood hmm how would that look like? 🤔
idk for sure but you can try
i cant remember if js has a placeholder like _ in other langs
Unfortunatly i behaves the same
but it doesnt error ts wise yea?
i would read through this specifically
https://tanstack.com/query/v4/docs/react/guides/important-defaults there are more than just refetchonwindowfocus that might also be triggering that u may not want
Important Defaults | TanStack Query Docs
Out of the box, React Query is configured with aggressive but sane defaults. Sometimes these defaults can catch new users off guard or make learning/debugging difficult if they are unknown by the user. Keep them in mind as you continue to learn and use React Query:
Query instances via useQuery or useInfiniteQuery by default consider cached dat...
Thanks I am going to have a look
I think I got it I am doing this now in my
_app.tsx
which is fine for now,
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@lee thanks that is even better 👍
@lee do you know a way to disable this per query?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thanks!
You can also change these options on a broader level:
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
If set to true, the query will refetch on reconnect if the data is stale. If set to false, the query will not refetch on reconnect. If set to 'always', the query will always refetch on reconnect. If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to the value of networkOnline (true)
triggered whenever connection is lost then restored