Skip to content

Commit c369169

Browse files
committed
docs: infinite query example
to only keep the first page
1 parent f76783c commit c369169

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

docs/react/guides/infinite-queries.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ useInfiniteQuery({
199199

200200
## What if I want to manually update the infinite query?
201201

202-
Manually removing first page:
202+
### Manually removing first page:
203203

204204
[//]: # 'Example6'
205205

@@ -212,7 +212,7 @@ queryClient.setQueryData(['projects'], (data) => ({
212212

213213
[//]: # 'Example6'
214214

215-
Manually removing a single value from an individual page:
215+
### Manually removing a single value from an individual page:
216216

217217
[//]: # 'Example7'
218218

@@ -230,4 +230,17 @@ queryClient.setQueryData(['projects'], (data) => ({
230230

231231
[//]: # 'Example7'
232232

233-
Make sure to keep the same data structure of pages and pageParams!
233+
### Keep only the first page:
234+
235+
[//]: # 'Example8'
236+
237+
```tsx
238+
queryClient.setQueryData(['projects'], (data) => ({
239+
pages: data.pages.slice(0,1),
240+
pageParams: data.pages.slice(0,1),
241+
}))
242+
```
243+
244+
[//]: # 'Example8'
245+
246+
Make sure to always keep the same data structure of pages and pageParams!

docs/vue/guides/infinite-queries.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,3 @@ const skipToCursor50 = () => fetchNextPage({ pageParam: 50 })
7171
```
7272

7373
[//]: # 'Example3'
74-
[//]: # 'Example7'
75-
76-
```tsx
77-
const newPagesArray =
78-
oldPagesArray?.pages.map((page) =>
79-
page.filter((val) => val.id !== updatedId),
80-
) ?? []
81-
82-
queryClient.setQueryData(['projects'], (data) => ({
83-
pages: newPagesArray,
84-
pageParams: data.pageParams,
85-
}))
86-
```
87-
88-
[//]: # 'Example7'

0 commit comments

Comments
 (0)