Skip to content

Commit f9c1cf0

Browse files
committed
Merge branch 'master' into next
2 parents 468828c + 14afce6 commit f9c1cf0

File tree

7 files changed

+202
-820
lines changed

7 files changed

+202
-820
lines changed

docs/ReferenceArrayField.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ You can change how the list of related records is rendered by passing a custom c
8787
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'tags' |
8888
| `children` | Optional&nbsp;* | `ReactNode` | `<SingleFieldList>` | One or several elements that render a list of records based on a `ListContext` |
8989
| `render` | Optional&nbsp;* | `(listContext) => Element` | `<SingleFieldList>` | A function that takes a list context and render a list of records |
90+
| `empty` | Optional | `ReactNode` | - | The component to render when the related records list is empty |
91+
| `error` | Optional | `ReactNode` | - | The component to render when an error occurs while fetching the related records |
9092
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records (the filtering is done client-side) |
93+
| `loading` | Optional | `ReactNode` | `<LinearProgress>` | The component to render while fetching the related records |
9194
| `offline` | Optional | `ReactNode` | `<Offline variant="inline" />` | The component to render when there is no connectivity and the record isn't in the cache |
9295
| `pagination` | Optional | `ReactNode` | - | Pagination element to display pagination controls. empty by default (no pagination) |
9396
| `perPage` | Optional | `number` | 1000 | Maximum number of results to display |
@@ -186,6 +189,66 @@ export const PostShow = () => (
186189
);
187190
```
188191

192+
## `empty`
193+
194+
By default, `<ReferenceArrayField>` renders its children when the related records list is empty. You can customize what is rendered by providing your own component via the `empty` prop:
195+
196+
```jsx
197+
import { ReferenceArrayField, Show, SimpleShowLayout } from 'react-admin';
198+
199+
export const PostShow = () => (
200+
<Show>
201+
<SimpleShowLayout>
202+
<ReferenceArrayField
203+
source="tag_ids"
204+
reference="tags"
205+
empty={<p>No tags found.</p>}
206+
/>
207+
</SimpleShowLayout>
208+
</Show>
209+
);
210+
```
211+
212+
You can also have `<ReferenceArrayField>` render nothing in that case by setting the prop to `null`:
213+
214+
```jsx
215+
<ReferenceArrayField
216+
source="tag_ids"
217+
reference="tags"
218+
empty={null}
219+
/>
220+
```
221+
222+
## `error`
223+
224+
By default, `<ReferenceArrayField>` renders its children when an error occurs while fetching the related records. You can customize what is rendered by providing your own component via the `error` prop:
225+
226+
```jsx
227+
import { ReferenceArrayField, Show, SimpleShowLayout } from 'react-admin';
228+
229+
export const PostShow = () => (
230+
<Show>
231+
<SimpleShowLayout>
232+
<ReferenceArrayField
233+
source="tag_ids"
234+
reference="tags"
235+
error={<p>Error loading tags. Please try again.</p>}
236+
/>
237+
</SimpleShowLayout>
238+
</Show>
239+
);
240+
```
241+
242+
You can also have `<ReferenceArrayField>` render nothing in that case by setting the prop to `null`:
243+
244+
```jsx
245+
<ReferenceArrayField
246+
source="tag_ids"
247+
reference="tags"
248+
error={null}
249+
/>
250+
```
251+
189252
## `filter`
190253

191254
`<ReferenceArrayField>` fetches all the related records, and displays them all, too. You can use the `filter` prop to filter the list of related records to display (this works by filtering the records client-side, after the fetch).
@@ -228,6 +291,37 @@ React-admin uses [the i18n system](./Translation.md) to translate the label, so
228291
<ReferenceArrayField label="resource.posts.fields.tags" source="tag_ids" reference="tags" />
229292
```
230293

294+
## `loading`
295+
296+
By default, `<ReferenceArrayField>` renders a `<LinearProgress>` component while fetching the related records. You can customize what is rendered by providing your own component via the `loading` prop:
297+
298+
```jsx
299+
import { ReferenceArrayField, Show, SimpleShowLayout } from 'react-admin';
300+
import { CircularProgress } from '@mui/material';
301+
302+
export const PostShow = () => (
303+
<Show>
304+
<SimpleShowLayout>
305+
<ReferenceArrayField
306+
source="tag_ids"
307+
reference="tags"
308+
loading={<CircularProgress />}
309+
/>
310+
</SimpleShowLayout>
311+
</Show>
312+
);
313+
```
314+
315+
You can also have `<ReferenceArrayField>` render nothing in that case by setting the prop to `null`:
316+
317+
```jsx
318+
<ReferenceArrayField
319+
source="tag_ids"
320+
reference="tags"
321+
loading={null}
322+
/>
323+
```
324+
231325
## `offline`
232326

233327
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:

0 commit comments

Comments
 (0)