Skip to main content
Initial query data allows you to provide pre-populated data to a query before it fetches. This is useful when you have data from server-side rendering, local storage, or other sources that can be used immediately while fresh data is being fetched in the background.

Basic Usage

Provide initial data using the initialData option:
When initialData is provided, the query will immediately be in a success state with the initial data, but it will still fetch in the background if the data is stale.

Initial Data Function

You can also provide a function that returns initial data. This is useful for deriving initial data from other queries:

Initial Data Updated At

Control when initial data is considered stale using initialDataUpdatedAt:
1

Set initialData

Provide the cached data to immediately render content
2

Set initialDataUpdatedAt

Specify when the data was cached (timestamp in milliseconds)
3

Configure staleTime

If the current time minus initialDataUpdatedAt is less than staleTime, the query won’t refetch

Type Safety

The initialData must match the query’s data type:

Behavior with Fetching State

Even with initialData, queries will still fetch if the data is stale:
The query state will be success immediately, but isFetching will be true while the background fetch is in progress.

Working with Falsy Values

Falsy values like 0, false, or '' are valid initial data:

When to Use Initial Data

Use initialData when:
  • You have data from server-side rendering (SSR)
  • You’re deriving data from another query in the cache
  • You have cached data from local storage
  • You want to provide a default value while fetching
For loading states, consider using placeholderData instead.

Differences from Placeholder Data

See Also