Skip to content

Commit 8382e14

Browse files
committed
Documentation
1 parent 9ed6d01 commit 8382e14

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

docs/Inputs.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ http://myapi.com/tags?id=[1,23,4]
14061406
http://myapi.com/tags?page=1&perPage=25
14071407
```
14081408

1409-
Once it receives the deduplicated reference resources, this component delegates rendering to a subcomponent, to which it passes the possible choices as the `choices` attribute.
1409+
Once it receives the deduplicated reference resources, this component delegates rendering to a subcomponent, by providing the possible choices through the `ReferenceArrayInputContext`. This context value can be accessed with the [`useReferenceArrayInputContext`](#usereferencearrayinputcontext) hook.
14101410

14111411
This means you can use `<ReferenceArrayInput>` with [`<SelectArrayInput>`](#selectarrayinput), or with the component of your choice, provided it supports the `choices` attribute.
14121412

@@ -1477,8 +1477,31 @@ You can tweak how this component fetches the possible values using the `perPage`
14771477
```
14781478
{% endraw %}
14791479

1480+
In addition to the `ReferenceArrayInputContext`, the `<ReferenceArrayInput>` also set up a `ListContext` providing access to the records from the reference resource in a similar fashion as of the `<List>` component. This `ListContext` value is accessible with the [`useListContext`](/List.md#uselistcontext) hook.
1481+
14801482
`<ReferenceArrayInput>` also accepts the [common input props](./Inputs.md#common-input-props).
14811483

1484+
### `useReferenceArrayInputContext`
1485+
1486+
The [`<ReferenceArrayInput>`](#referencearrayinput) component take care of fetching the data, and put that data in a context called `ReferenceArrayInputContext` so that it’s available for its descendants. This context also stores filters, pagination, sort state, and provides callbacks to update them.
1487+
1488+
Any component can grab information from the `ReferenceArrayInputContext` using the `useReferenceArrayInputContext` hook. Here is what it returns:
1489+
1490+
```js
1491+
const {
1492+
choices, // An array of records mathcing both the current input value and the filters
1493+
error, // A potential error which may have occured while fetching the data
1494+
warning, // A potential warning regarding missing references
1495+
loaded, // boolean that is false until the data is available
1496+
loading, // boolean that is true on mount, and false once the data was fetched
1497+
setFilter, // a callback to update the filters, e.g. setFilters({ q: 'query' })
1498+
setPagination, // a callback to change the pagination, e.g. setPagination({ page: 2, perPage: 50 })
1499+
setSort, // a callback to change the sort, e.g. setSort({ field: 'name', order: 'DESC' })
1500+
1501+
setSortForList, // // a callback to set the sort with the same signature as the one from the ListContext. This is required to not break backward compatibility and will be removed in v4.
1502+
}
1503+
```
1504+
14821505
### `<ReferenceInput>`
14831506

14841507
Use `<ReferenceInput>` for foreign-key values, for instance, to edit the `post_id` of a `comment` resource. This component fetches the related record (using `dataProvider.getMany()`) as well as possible choices (using `dataProvider.getList()` in the reference resource), then delegates rendering to a subcomponent, to which it passes the possible choices as the `choices` attribute.

0 commit comments

Comments
 (0)