Basic Usage
Provide initial data using theinitialData 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 usinginitialDataUpdatedAt:
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 refetchType Safety
TheinitialData must match the query’s data type:
Behavior with Fetching State
Even withinitialData, queries will still fetch if the data is stale:
Working with Falsy Values
Falsy values like0, false, or '' are valid initial data:
When to Use Initial Data
Differences from Placeholder Data
See Also
- Placeholder Data - For temporary placeholder content
- Prefetching - For loading data before it’s needed
- SSR & Hydration - For server-side rendering patterns