Skip to content

Commit 8a4ab01

Browse files
committed
Improve documentation
1 parent e9c7492 commit 8a4ab01

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

packages/ra-core/src/controller/field/ArrayFieldBase.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ import type { BaseFieldProps } from './types';
1515
*
1616
* @example
1717
* const PostShow = () => (
18-
* <Show>
19-
* <SimpleShowLayout>
20-
* <ArrayFieldBase source="tags">
21-
* <WithListContext
22-
* render={({ data }) => (
23-
* <ul>
24-
* {data.map(tag => (
25-
* <li key={tag.name}>{tag.name}</li>
26-
* ))}
27-
* </ul>
28-
* )}
29-
* />
30-
* </ArrayFieldBase>
31-
* </SimpleShowLayout>
32-
* </Show>
18+
* <ShowBase>
19+
* <ArrayFieldBase source="tags">
20+
* <ul>
21+
* <RecordsIterator
22+
* render={record => <li key={record.id}>{record.name}</li>}
23+
* />
24+
* </ul>
25+
* </ArrayFieldBase>
26+
* </ShowBase>
3327
* );
3428
*
3529
* @see useListContext

packages/ra-ui-materialui/src/field/ArrayField.stories.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
TestMemoryRouter,
99
ResourceContextProvider,
1010
downloadCSV,
11+
RecordsIterator,
1112
} from 'ra-core';
1213
import polyglotI18nProvider from 'ra-i18n-polyglot';
1314
import englishMessages from 'ra-language-english';
@@ -42,6 +43,18 @@ export const Basic = () => (
4243
</TestMemoryRouter>
4344
);
4445

46+
export const WithRecordsIterator = () => (
47+
<TestMemoryRouter>
48+
<ArrayField record={{ id: 123, books }} source="books">
49+
<ul>
50+
<RecordsIterator
51+
render={record => <li key={record.id}>{record.title}</li>}
52+
/>
53+
</ul>
54+
</ArrayField>
55+
</TestMemoryRouter>
56+
);
57+
4558
const i18nProvider = polyglotI18nProvider(() => englishMessages);
4659

4760
export const PerPage = () => (

packages/ra-ui-materialui/src/field/ArrayField.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@ import { ArrayFieldBase, type ArrayFieldBaseProps } from 'ra-core';
22

33
import type { FieldProps } from './types';
44

5+
/**
6+
* Renders an embedded array of objects.
7+
*
8+
* ArrayField creates a ListContext with the field value, and renders its
9+
* children components - usually iterator components.
10+
*
11+
* @example
12+
* const PostShow = () => (
13+
* <Show>
14+
* <SimpleShowLayout>
15+
* <ArrayField source="tags">
16+
* <SingleFieldList>
17+
* <ChipField source="name" />
18+
* </SingleFieldList>
19+
* </ArrayField>
20+
* </SimpleShowLayout>
21+
* </Show>
22+
* );
23+
*
24+
* @see useListContext
25+
*/
526
export const ArrayField = ArrayFieldBase;
627

728
export interface ArrayFieldProps<

0 commit comments

Comments
 (0)