Skip to content

Commit d8c1f4f

Browse files
committed
Added usage examples and explanations for the new storeKey property in ArrayField
1 parent bd5b4a4 commit d8c1f4f

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

docs/ArrayField.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ const PostShow = () => (
7171

7272
## Props
7373

74-
| Prop | Required | Type | Default | Description |
75-
|------------|----------|-------------------|---------|------------------------------------------|
76-
| `children` | Required | `ReactNode` | | The component to render the list. |
77-
| `filter` | Optional | `object` | | The filter to apply to the list. |
78-
| `perPage` | Optional | `number` | 1000 | The number of items to display per page. |
79-
| `sort` | Optional | `{ field, order}` | | The sort to apply to the list. |
74+
| Prop | Required | Type | Default | Description |
75+
|------------|----------|-------------------|---------|----------------------------------------------------|
76+
| `children` | Required | `ReactNode` | | The component to render the list. |
77+
| `filter` | Optional | `object` | | The filter to apply to the list. |
78+
| `perPage` | Optional | `number` | 1000 | The number of items to display per page. |
79+
| `sort` | Optional | `{ field, order}` | | The sort to apply to the list. |
80+
| `storeKey` | Optional | `string` | | The key to use to store the records selection state|
8081

8182
`<ArrayField>` accepts the [common field props](./Fields.md#common-field-props), except `emptyText` (use the child `empty` prop instead).
8283

@@ -217,6 +218,35 @@ By default, `<ArrayField>` displays the items in the order they are stored in th
217218
```
218219
{% endraw %}
219220

221+
## `storeKey`
222+
223+
By default, `ArrayField` stores the selection state in localStorage so users can revisit the page and find the selection preserved. The key for storing this state is based on the resource name, formatted as `${resource}.selectedIds`.
224+
225+
When displaying multiple lists with the same data source, you may need to distinguish their selection states. To achieve this, assign a unique `storeKey` to each `ArrayField`. This allows each list to maintain its own selection state independently.
226+
227+
In the example below, two `ArrayField` components display the same data source (`books`), but each stores its selection state under a different key (`books.selectedIds` and `custom.selectedIds`). This ensures that both components can coexist on the same page without interfering with each other's state.
228+
229+
```jsx
230+
<Stack direction="row" spacing={2}>
231+
<ArrayField
232+
source="books"
233+
storeKey="customOne"
234+
>
235+
<Datagrid>
236+
<TextField source="title" />
237+
</Datagrid>
238+
</ArrayField>
239+
<ArrayField
240+
source="books"
241+
storeKey="customTwo"
242+
>
243+
<Datagrid>
244+
<TextField source="title" />
245+
</Datagrid>
246+
</ArrayField>
247+
</Stack>
248+
```
249+
220250
## Using The List Context
221251

222252
`<ArrayField>` creates a [`ListContext`](./useListContext.md) with the field value, so you can use any of the list context values in its children. This includes callbacks to sort, filter, and select items.

0 commit comments

Comments
 (0)