You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/Admin.md
+76
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,7 @@ Here are all the props accepted by the component:
32
32
-[`dataProvider`](#dataprovider)
33
33
-[`authProvider`](#authprovider)
34
34
-[`i18nProvider`](#i18nprovider)
35
+
-[`queryClient`](#queryclient)
35
36
-[`title`](#title)
36
37
-[`dashboard`](#dashboard)
37
38
-[`disableTelemetry`](#disabletelemetry)
@@ -95,6 +96,81 @@ The [Auth Provider documentation](./Authentication.md) explains how to implement
95
96
96
97
The `i18nProvider` props let you translate the GUI. The [Translation Documentation](./Translation.md) details this process.
97
98
99
+
## `queryClient`
100
+
101
+
React-admin uses [react-query](https://react-query.tanstack.com/) to fetch, cache and update data. Internally, the `<Admin>` component creates a react-query [`QueryClient`](https://react-query.tanstack.com/reference/QueryClient) on mount, using [react-query's "aggressive but sane" defaults](https://react-query.tanstack.com/guides/important-defaults):
102
+
103
+
* Queries consider cached data as stale
104
+
* Stale queries are refetched automatically in the background when:
105
+
* New instances of the query mount
106
+
* The window is refocused
107
+
* The network is reconnected
108
+
* The query is optionally configured with a refetch interval
109
+
* Query results that are no longer used in the current page are labeled as "inactive" and remain in the cache in case they are used again at a later time.
110
+
* By default, "inactive" queries are garbage collected after 5 minutes.
111
+
* Queries that fail are silently retried 3 times, with exponential backoff delay before capturing and displaying an error to the UI.
112
+
* Query results by default are structurally shared to detect if data has actually changed and if not, the data reference remains unchanged to better help with value stabilization with regards to `useMemo` and `useCallback`.
113
+
114
+
If you want to override the react-query default query and mutation default options, or use a specific client or mutation cache, you can create your own `QueryClient` instance and pass it to the `<Admin queryClient>` prop:
To know which options you can pass to the `QueryClient` constructor, check the [react-query documentation](https://react-query.tanstack.com/reference/QueryClient) and the [query options](https://react-query.tanstack.com/reference/useQuery) and [mutation options](https://react-query.tanstack.com/reference/useMutation) sections.
140
+
141
+
The common settings that react-admin developers often overwrite are:
142
+
143
+
```jsx
144
+
import { QueryClient } from'react-query';
145
+
146
+
constqueryClient=newQueryClient({
147
+
defaultOptions: {
148
+
queries: {
149
+
/**
150
+
* The time in milliseconds after data is considered stale.
151
+
* If set to `Infinity`, the data will never be considered stale.
152
+
*/
153
+
staleTime:10000,
154
+
/**
155
+
* If `false`, failed queries will not retry by default.
156
+
* If `true`, failed queries will retry infinitely., failureCount: num
157
+
* If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number.
158
+
* If set to a function `(failureCount, error) => boolean` failed queries will retry until the function returns false.
159
+
*/
160
+
retry:false,
161
+
/**
162
+
* If set to `true`, the query will refetch on window focus if the data is stale.
163
+
* If set to `false`, the query will not refetch on window focus.
164
+
* If set to `'always'`, the query will always refetch on window focus.
165
+
* If set to a function, the function will be executed with the latest data and query to compute the value.
166
+
* Defaults to `true`.
167
+
*/
168
+
refetchOnWindowFocus:false,
169
+
},
170
+
},
171
+
});
172
+
```
173
+
98
174
## `title`
99
175
100
176
On error pages, the header of an admin app uses 'React Admin' as the main app title. Use the `title` to customize it.
Copy file name to clipboardexpand all lines: docs/DataProviders.md
+26
Original file line number
Diff line number
Diff line change
@@ -365,6 +365,32 @@ export default App;
365
365
366
366
**Tip**: This example uses the function version of `setState` (`setDataProvider(() => dataProvider))`) instead of the more classic version (`setDataProvider(dataProvider)`). This is because some legacy Data Providers are actually functions, and `setState` would call them immediately on mount.
367
367
368
+
## Default Query Options
369
+
370
+
If you often need to pass the same query options to the data provider, you can use [the `<Admin queryClient>` prop](./Admin.md#queryclient) to set them globally.
To know which query options you can override, check the [Querying the API documentation](./Actions.md#query-options) and [the `<Admin queryClient>` prop documentation](./Admin.md#queryclient).
393
+
368
394
## Combining Data Providers
369
395
370
396
If you need to build an app relying on more than one API, you may face a problem: the `<Admin>` component accepts only one `dataProvider` prop. You can combine multiple data providers into one using the `combineDataProviders` helper. It expects a function as parameter accepting a resource name and returning a data provider for that resource.
0 commit comments