Skip to main content
Placeholder data allows you to display temporary content while a query is fetching. Unlike initialData, placeholder data is not persisted to the cache and doesn’t affect the query’s state.

Basic Usage

Provide placeholder data using the placeholderData option:
The isPlaceholderData flag tells you when you’re showing placeholder data vs. real data.

Keep Previous Data

A common pattern is keeping the previous query’s data while fetching new data. Use the keepPreviousData helper:
The keepPreviousData function returns the previous data when available, preventing content from disappearing during pagination or filtering.

Placeholder Data Function

Compute placeholder data dynamically using a function:

With Select Transform

Placeholder data works correctly with select transforms:
1

Previous data is kept

The previous query result is used as placeholder data
2

Select function runs

The select transform runs on the placeholder data
3

New data replaces placeholder

When the fetch completes, real data replaces the placeholder

Query State Behavior

Placeholder data affects the query state differently than initial data:
Placeholder data does not change the query status to success. The query remains in pending state until real data is fetched.

Pagination Example

A complete pagination example using keepPreviousData:

TypeScript

Placeholder data must match the query’s data type:

When to Use Placeholder Data

Use placeholderData when:
  • You want to keep previous results during pagination
  • You’re implementing optimistic UI updates
  • You want to show a skeleton or loading state with partial data
  • You need temporary data that shouldn’t be cached
For pre-populating with real data, use initialData instead.

keepPreviousData Implementation

The keepPreviousData helper is a simple function that returns the previous data:
Source: packages/query-core/src/utils.ts:407

Differences from Initial Data

See Also