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

query-cancellation.md

34 lines752 Bytes

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