Open History to see the last commit
1---
2id: query-retries
3title: Query Retries
4ref: docs/framework/react/guides/query-retries.md
5replace:
6 {
7 'Provider': 'Plugin',
8 'useQuery': 'injectQuery',
9 'useMutation': 'injectMutation',
10 }
11---
12β
13[//]: # 'Info'
14[//]: # 'Info'
15[//]: # 'Example'
16β
17```ts
18import { injectQuery } from '@tanstack/angular-query'
19β
20// Make a specific query retry a certain number of times
21const todoQuery = injectQuery(() => ({
22 queryKey: ['todos', 1],
23 queryFn: fetchTodoListPage,
24 retry: 10, // Will retry failed requests 10 times before displaying an error
25}))
26```
27β
28[//]: # 'Example'
29[//]: # 'Example2'
30β
31```ts
32// Configure for all queries
33import {
34 QueryCache,
35 QueryClient,
36 QueryClientProvider,
37} from '@tanstack/angular-query'
38β
39const createQueryClient = () =>
40 new QueryClient({
41 defaultOptions: {
42 queries: {
43 retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
44 },
45 },
46 })
47β
48bootstrapApplication(AppComponent, {
49 providers: [provideTanStackQuery(createQueryClient)],
50})
51```
52β
53[//]: # 'Example2'
54β
55Though it is not recommended, you can obviously override the `retryDelay` function/integer in both the Provider and individual query options. If set to an integer instead of a function the delay will always be the same amount of time:
56β
57[//]: # 'Example3'
58β
59```ts
60const todosQuery = injectQuery(() => ({
61 queryKey: ['todos'],
62 queryFn: fetchTodoList,
63 retryDelay: 1000, // Will always wait 1000ms to retry, regardless of how many retries
64}))
65```
66β
67[//]: # 'Example3'