Many queries when switching tabs

Whats the default behaviour of prisma and trpc when you click to a different tab and back. I'm getting lots of queries everytime i do this. Wondering if it's something to do with the dev server setup or if I might have something else going on.
5 Replies
Sugan_Selvam
Sugan_Selvam•2y ago
add this block inside /utils/api.ts inside createTRPCNext queryClientConfig: { defaultOptions: { queries: { // refetchOnMount: false, refetchOnWindowFocus: false, }, }, }, Basically React-query by default, will trigger the fetch request every time browser window is switched and comes back. This should prevent it and only trigger based on your component's logic
gnarley_farley.
gnarley_farley.•2y ago
Hell yeah sugan, thanks Are there any negative implications to doing this across the app?
prakhar_goel
prakhar_goel•2y ago
One downside to doing this at a global level can be users might get outdated or incorrect data if they come back after a while which can be days. I prefer to do it at a query level instead of doing it globally.
TkDodo 🔮
TkDodo 🔮•2y ago
The better approach would be to customize staleTime: https://tkdodo.eu/blog/react-query-as-a-state-manager
React Query as a State Manager
Everything you need to know to make React Query your single source of truth state manager for your async state
gnarley_farley.
gnarley_farley.•2y ago
I just disabled it globally for now. Seems to work, I'm building a blogging platform for coders. It's not exactly something that requires live updates constantly. Every action that needs an update has some sort of mechanism for triggering a fetch already. But thank you for the suggestions I will investigate further when I get to optimizing.
Want results from more Discord servers?
Add your server