T
TanStack6mo ago
evident-indigo

React Native - React Query re-fetches on all mounted screen after query invalidation

In React Native, screens don’t unmount when navigating between them. So if a user moves through, say, 10 screens, each one remains mounted. Because of this, any time I invalidate a query (which I do when changes are detected since the app is local-first and uses a SQL database), every screen that’s still mounted re-fetches its data immediately — even if it’s not in focus. This creates a cascade of React Query invalidations and database queries. As a workaround, I’ve started passing a subscribed boolean based on whether the screen is in focus, to prevent re-fetching when it’s not. Would you consider this behavior a React Query bug? Or a feature request?
1 Reply
harsh-harlequin
harsh-harlequin6mo ago
Subscribed is the recommendation way for RN

Did you find this page helpful?