Skip to content
0

katanakit-js / keepPreviousData

Function: keepPreviousData() ​

ts
function keepPreviousData<T>(previousData): T | undefined;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:1022

Intended to be passed as a query's placeholderData option, for example placeholderData: keepPreviousData. Instead of resetting the query's data to undefined while a new query key is fetching, it keeps displaying the previously fetched data until the new data arrives.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
previousDataT | undefined

Returns ​

T | undefined

Example ​

ts
new QueryObserver(queryClient, {
  queryKey: ['posts', page],
  queryFn: () => fetchPosts(page),
  placeholderData: keepPreviousData,
})

Released under the MIT License.