Open History to see the last commit
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'] })
31}
32```
33β
34[//]: # 'Example7'