Skip to content

Commit f97d725

Browse files
docs: mention second parameter for cancelQueries (#9597)
Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
1 parent 0650eaf commit f97d725

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

docs/framework/react/guides/query-cancellation.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ return (
188188

189189
[//]: # 'Example7'
190190

191+
## `Cancel Options`
192+
193+
Cancel options are used to control the behavior of query cancellation operations.
194+
195+
```tsx
196+
// Cancel specific queries silently
197+
await queryClient.cancelQueries({ queryKey: ['posts'] }, { silent: true })
198+
```
199+
200+
A cancel options object supports the following properties:
201+
202+
- `silent?: boolean`
203+
- When set to `true`, suppresses propagation of `CancelledError` to observers (e.g., `onError` callbacks) and related notifications, and returns the retry promise instead of rejecting.
204+
- Defaults to `false`
205+
- `revert?: boolean`
206+
- When set to `true`, restores the query’s state (data and status) from immediately before the in-flight fetch, sets `fetchStatus` back to `idle`, and only throws if there was no prior data.
207+
- Defaults to `true`
208+
191209
## Limitations
192210

193211
Cancellation does not work when working with `Suspense` hooks: `useSuspenseQuery`, `useSuspenseQueries` and `useSuspenseInfiniteQuery`.

docs/reference/QueryClient.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,16 @@ The `cancelQueries` method can be used to cancel outgoing queries based on their
403403
This is most useful when performing optimistic updates since you will likely need to cancel any outgoing query refetches so they don't clobber your optimistic update when they resolve.
404404

405405
```tsx
406-
await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
406+
await queryClient.cancelQueries(
407+
{ queryKey: ['posts'], exact: true },
408+
{ silent: true },
409+
)
407410
```
408411

409412
**Options**
410413

411414
- `filters?: QueryFilters`: [Query Filters](../../framework/react/guides/filters.md#query-filters)
415+
- `cancelOptions?: CancelOptions`: [Cancel Options](../../framework/react/guides/query-cancellation.md#cancel-options)
412416

413417
**Returns**
414418

0 commit comments

Comments
 (0)