Basic Prefetching
UseprefetchQuery to load data into the cache:
prefetchQuery API
TheprefetchQuery method has the same signature as fetchQuery but doesn’t return data:
Prefetch Options
Configure how prefetched data behaves:1
Query is fetched
Data is fetched and stored in the cache
2
Cache entry created
A cache entry is created with the specified options
3
Data becomes available
When the component mounts, data is instantly available
Prefetching in Route Loaders
Prefetch data in route loaders for instant navigation:Prefetch on User Intent
Prefetch based on user behavior patterns:Prefetch Infinite Queries
Prefetch infinite queries usingprefetchInfiniteQuery:
Conditional Prefetching
Only prefetch when data isn’t already cached:Prefetching automatically respects
staleTime. If data exists and isn’t stale, it won’t refetch.Prefetch with Dependencies
Prefetch related data together:Experimental: Prefetch in Render
Enable prefetching during component rendering (experimental):Prefetch Strategies
On Mount
Prefetch when a parent component mounts:On Interaction
Prefetch on specific user interactions:On Scroll
Prefetch next page before user reaches the end:Best Practices
See Also
- Initial Data - For setting data before fetching
- SSR & Hydration - For server-side prefetching
- Query Keys - For structuring cache keys