Skip to content

Commit c2a6fe7

Browse files
authored
Merge pull request #9200 from marmelab/doc-data-provider
[Doc] Update the Data Fetching documentation
2 parents 923b63d + 896f00b commit c2a6fe7

22 files changed

+613
-269
lines changed

docs/Actions.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ Refer to [the `useDataProvider` hook documentation](./useDataProvider.md) for mo
3030

3131
React-admin provides one hook for each of the Data Provider methods. They are useful shortcuts that make your code more readable and more robust.
3232

33+
The query hooks execute on mount. They return an object with the following properties: `{ data, isLoading, error }`. Query hooks are:
34+
35+
* [`useGetList`](./useGetList.md)
36+
* [`useGetOne`](./useGetOne.md)
37+
* [`useGetMany`](./useGetMany.md)
38+
* [`useGetManyReference`](./useGetManyReference.md)
39+
40+
The mutation hooks execute the query when you call a callback. They return an array with the following items: `[mutate, { data, isLoading, error }]`. Mutation hooks are:
41+
42+
* [`useCreate`](./useCreate.md)
43+
* [`useUpdate`](./useUpdate.md)
44+
* [`useUpdateMany`](./useUpdateMany.md)
45+
* [`useDelete`](./useDelete.md)
46+
* [`useDeleteMany`](./useDeleteMany.md)
47+
3348
Their signature is the same as the related dataProvider method, e.g.:
3449

3550
```jsx
@@ -59,29 +74,7 @@ const UserProfile = ({ userId }) => {
5974
};
6075
```
6176

62-
**Tip**: If you use TypeScript, you can specify the record type for more type safety:
63-
64-
```jsx
65-
const { data, isLoading } = useGetOne<Product>('products', { id: 123 });
66-
// \- type of data is Product
67-
```
68-
69-
The query hooks execute on mount. They return an object with the following properties: `{ data, isLoading, error }`. Query hooks are:
70-
71-
* [`useGetList`](./useGetList.md)
72-
* [`useGetOne`](./useGetOne.md)
73-
* [`useGetMany`](./useGetMany.md)
74-
* [`useGetManyReference`](./useGetManyReference.md)
75-
76-
The mutation hooks execute the query when you call a callback. They return an array with the following items: `[mutate, { data, isLoading, error }]`. Mutation hooks are:
77-
78-
* [`useCreate`](./useCreate.md)
79-
* [`useUpdate`](./useUpdate.md)
80-
* [`useUpdateMany`](./useUpdateMany.md)
81-
* [`useDelete`](./useDelete.md)
82-
* [`useDeleteMany`](./useDeleteMany.md)
83-
84-
For instance, here is an example using `useUpdate()`:
77+
Here is another example, using `useUpdate()`:
8578

8679
```jsx
8780
import * as React from 'react';
@@ -104,6 +97,13 @@ const { data: user, isLoading, error } = useGetOne(
10497
);
10598
```
10699

100+
**Tip**: If you use TypeScript, you can specify the record type for more type safety:
101+
102+
```jsx
103+
const { data, isLoading } = useGetOne<Product>('products', { id: 123 });
104+
// \- type of data is Product
105+
```
106+
107107
## `meta` Parameter
108108

109109
All Data Provider methods accept a `meta` parameter. React-admin doesn't set this parameter by default in its queries, but it's a good way to pass special arguments or metadata to an API call.
@@ -227,12 +227,12 @@ const dataProvider = {
227227
getList: /* ... */,
228228
getOne: /* ... */,
229229
getMany: /* ... */,
230-
getManyReference /* ... */,
230+
getManyReference: /* ... */,
231231
create: /* ... */,
232232
update: /* ... */,
233-
updateMany /* ... */,
233+
updateMany: /* ... */,
234234
delete: /* ... */,
235-
deleteMany /* ... */,
235+
deleteMany: /* ... */,
236236
banUser: (userId) => {
237237
return fetch(`/api/user/${userId}/ban`, { method: 'POST' })
238238
.then(response => response.json());

docs/Admin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const dataProvider = {
200200

201201
Check the [Writing a Data Provider](./DataProviderWriting.md) chapter for detailed instructions on how to write a data provider for your API.
202202

203-
The `dataProvider` is also the ideal place to add custom HTTP headers, handle file uploads, map resource names to API endpoints, pass credentials to the API, put business logic, reformat API errors, etc. Check [the Data Provider documentation](./DataProviderIntroduction.md) for more details.
203+
The `dataProvider` is also the ideal place to add custom HTTP headers, handle file uploads, map resource names to API endpoints, pass credentials to the API, put business logic, reformat API errors, etc. Check [the Data Provider documentation](./DataProviders.md) for more details.
204204

205205
## `children`
206206

docs/DataProviderIntroduction.md

-46
This file was deleted.

0 commit comments

Comments
 (0)