Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

query-cancellation.md

25 lines449 Bytes

1---
2id: query-cancellation
3title: Query Cancellation
4ref: docs/framework/react/guides/query-cancellation.md
5---
6​
7[//]: # 'Example7'
8​
9```ts
10const query = useQuery({
11 queryKey: ['todos'],
12 queryFn: async ({ signal }) => {
13 const resp = await fetch('/todos', { signal })
14 return resp.json()
15 },
16})
17​
18const queryClient = useQueryClient()
19​
20function onButtonClick() {
21 queryClient.cancelQueries({ queryKey: ['todos'] })
23```
24​
25[//]: # 'Example7'