Open History to see the last commit
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'] })
22}
23```
24β
25[//]: # 'Example7'