Skip to main content
Prefetching allows you to fetch and cache data before a user needs it, creating instant page transitions and eliminating loading states.

Basic Prefetching

Use prefetchQuery to load data into the cache:
Prefetching on hover or mouseEnter provides data before the user clicks, making navigation feel instant.

prefetchQuery API

The prefetchQuery method has the same signature as fetchQuery but doesn’t return data:
Source: packages/query-core/src/queryClient.ts:372

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 using prefetchInfiniteQuery:
Source: packages/query-core/src/queryClient.ts:407

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):
The experimental_prefetchInRender feature is experimental and may change in future versions. It allows queries to start fetching during render instead of waiting for useEffect.
Source: packages/query-core/src/types.ts:438

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

  1. Prefetch on hover/focus: Most effective for navigation
  2. Set appropriate staleTime: Avoid redundant prefetches
  3. Don’t over-prefetch: Balance UX with data usage
  4. Use with route loaders: Great for SPA navigation
  5. Combine with Suspense: For React 18+ streaming SSR

See Also