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/Edit.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -542,7 +542,7 @@ The default `onError` function is:
542
542
543
543
## `offline`
544
544
545
-
By default, `<EditBase>` renders nothing when there is no connectivity and the record hasn't been cached yet. You can provide your own component via the `offline` prop:
545
+
By default, `<Edit>` renders the `<Offline>` component when there is no connectivity and the record hasn't been cached yet. You can provide your own component via the `offline` prop:
|`source`| Required |`string`| - | Name of the property to display |
87
87
|`reference`| Required |`string`| - | The name of the resource for the referenced records, e.g. 'tags' |
88
-
|`children`| Optional *|`Element`|`<SingleFieldList>`| One or several elements that render a list of records based on a `ListContext`|
88
+
|`children`| Optional *|`ReactNode`|`<SingleFieldList>`| One or several elements that render a list of records based on a `ListContext`|
89
89
|`render`| Optional *|`(listContext) => Element`|`<SingleFieldList>`| A function that takes a list context and render a list of records |
90
90
|`filter`| Optional |`Object`| - | Filters to use when fetching the related records (the filtering is done client-side) |
91
-
|`pagination`| Optional |`Element`| - | Pagination element to display pagination controls. empty by default (no pagination) |
91
+
|`offline`| Optional |`ReactNode`|`<Offline variant="inline" />`| The component to render when there is no connectivity and the record isn't in the cache |
92
+
|`pagination`| Optional |`ReactNode`| - | Pagination element to display pagination controls. empty by default (no pagination) |
92
93
|`perPage`| Optional |`number`| 1000 | Maximum number of results to display |
93
94
|`queryOptions`| Optional |[`UseQuery Options`](https://tanstack.com/query/v5/docs/react/reference/useQuery)|`{}`|`react-query` options for the `getMany` query |
94
95
|`sort`| Optional |`{ field, order }`|`{ field: 'id', order: 'DESC' }`| Sort order to use when displaying the related records (the sort is done client-side) |
@@ -235,6 +236,47 @@ React-admin uses [the i18n system](./Translation.md) to translate the label, so
By default, `<ReferenceArrayField>` renders the `<Offline variant="inline">` when there is no connectivity and the records haven't been cached yet. You can provide your own component via the `offline` prop:
242
+
243
+
```jsx
244
+
import { ReferenceArrayField, Show } from'react-admin';
245
+
import { Alert } from'@mui/material';
246
+
247
+
exportconstPostShow= () => (
248
+
<Show>
249
+
<ReferenceArrayField
250
+
source="tag_ids"
251
+
reference="tags"
252
+
offline={<Alert severity="warning">No network. Could not load the tags.</Alert>}
253
+
>
254
+
...
255
+
</ReferenceArrayField>
256
+
</Show>
257
+
);
258
+
```
259
+
260
+
**Tip**: If the records are in the Tanstack Query cache but you want to warn the user that they may see an outdated version, you can use the `<IsOffline>` component:
261
+
262
+
```jsx
263
+
import { IsOffline, ReferenceArrayField, Show } from'react-admin';
`<ReferenceArrayField>` fetches *all* the related fields, and puts them all in a `ListContext`. If a record has a large number of related records, you can limit the number of displayed records with the [`perPage`](#perpage) prop. Then, let users display remaining records by rendering pagination controls. For that purpose, pass a pagination element to the `pagination` prop.
Copy file name to clipboardExpand all lines: docs/ReferenceArrayFieldBase.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,7 @@ You can change how the list of related records is rendered by passing a custom c
92
92
| `children` | Optional\* | `Element` | | One or several elements that render a list of records based on a `ListContext` |
93
93
| `render` | Optional\* | `(ListContext) =>Element` | | A function that takes a list context and renders a list of records |
94
94
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records (the filtering is done client-side) |
95
+
| `offline` | Optional | `ReactNode` | | The component to render when there is no connectivity and the record isn't in the cache |
95
96
| `perPage` | Optional | `number` | 1000 | Maximum number of results to display |
96
97
| `queryOptions` | Optional | [`UseQuery Options`](https://tanstack.com/query/v5/docs/react/reference/useQuery) | `{}` | `react-query` options for the `getMany` query |
97
98
| `sort` | Optional | `{ field, order }` | `{ field:'id', order:'DESC' }` | Sort order to use when displaying the related records (the sort is done client-side) |
@@ -175,6 +176,49 @@ For instance, to render only tags that are 'published', you can use the followin
175
176
```
176
177
{% endraw %}
177
178
179
+
## `offline`
180
+
181
+
By default, `<ReferenceArrayFieldBase>` renders nothing when there is no connectivity and the records haven't been cached yet. You can provide your own component via the `offline` prop:
offline={<p>No network. Could not load the tags.</p>}
192
+
>
193
+
...
194
+
</ReferenceArrayFieldBase>
195
+
</ShowBase>
196
+
);
197
+
```
198
+
199
+
**Tip**: If the records are in the Tanstack Query cache but you want to warn the user that they may see an outdated version, you can use the `<IsOffline>` component:
offline={<p>No network. Could not load the tags.</p>}
210
+
>
211
+
<IsOffline>
212
+
<p>
213
+
You are offline, tags may be outdated
214
+
</p>
215
+
</IsOffline>
216
+
...
217
+
</ReferenceArrayFieldBase>
218
+
</ShowBase>
219
+
);
220
+
```
221
+
178
222
## `perPage`
179
223
180
224
`<ReferenceArrayFieldBase>` fetches *all* the related fields, and puts them all in a `ListContext`. If a record has a large number of related records, it may be a good idea to limit the number of displayed records. The `perPage` prop allows to create a client-side pagination for the related records.
0 commit comments