do i need to check cache before query?
do i actually need it? as i understand RQ will do this under the hood for me ?
3 Replies
flat-fuchsia•2y ago
If I'm not mistaken, it will check if the data is still there based on your queryKey. Let's say you mutate that data on the server, you can invalidate that key using
queryClient.invalidateQueries({queryKey: ['Todos']})
.
Have a look here how caching works: https://tanstack.com/query/v4/docs/react/guides/caching
And here for query invalidation: https://tanstack.com/query/v4/docs/react/guides/query-invalidationCaching Examples | TanStack Query Docs
Please thoroughly read the Important Defaults before reading this guide
Basic Example
Query Invalidation | TanStack Query Docs
Waiting for queries to become stale before they are fetched again doesn't always work, especially when you know for a fact that a query's data is out of date because of something the user has done. For that purpose, the QueryClient has an invalidateQueries method that lets you intelligently mark queries as stale and potentially refetch them too!
flat-fuchsia•2y ago
I'd recommend using the ReactQueryDevtools. It will show you exactly what it is fetching
@x4r7
continuing-cyanOP•2y ago
thanks