Open History to see the last commit
1---
2id: keepPreviousData
3title: keepPreviousData
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function keepPreviousData<T>(previousData: T | undefined): T | undefined;
10```
11β
12Defined in: [packages/query-core/src/utils.ts:582](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L582)
13β
14Intended to be passed as a query's `placeholderData` option, for example
15`placeholderData: keepPreviousData`. Instead of resetting the query's data to `undefined` while a new
16query key is fetching, it keeps displaying the previously fetched data until the new data arrives.
17β
18## Type Parameters
19β
20### T
21β
22`T`
23β
24## Parameters
25β
26### previousData
27β
28`T` \| `undefined`
29β
30The data of the previous query key, passed by the observer.
31β
32## Returns
33β
34`T` \| `undefined`
35β
36The previous data, unchanged.
37β
38## Example
39β
40```ts
41new QueryObserver(queryClient, {
42 queryKey: ['posts', page],
43 queryFn: () => fetchPosts(page),
44 placeholderData: keepPreviousData,
45})
46```