Skip to content

Commit 0de83ae

Browse files
authored
docs: Use higher order function (array) in code example (TanStack#2342)
* Use higher order function (array) in code example * Add coalesce operator to prevent `undefined` value
1 parent 976fdb7 commit 0de83ae

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

docs/src/pages/guides/infinite-queries.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ queryClient.setQueryData('projects', data => ({
158158
Manually removing a single value from an individual page:
159159

160160
```js
161-
const newPagesArray = []
162-
oldPagesArray?.pages.forEach(page => {
163-
const newData = page.filter(val => val.id !== updatedId)
164-
newPagesArray.push(newData)
165-
})
161+
const newPagesArray = oldPagesArray?.pages.map((page) =>
162+
page.filter((val) => val.id !== updatedId)
163+
) ?? []
164+
166165
queryClient.setQueryData('projects', data => ({
167166
pages: newPagesArray,
168167
pageParams: data.pageParams,

0 commit comments

Comments
 (0)