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
|`children`| Required if no render |`Element`| - | One or several elements that render a list of records based on a `ListContext`|
93
-
|`render`| Required if no children |`(listContext) => Element`| - | Function that receives a `ListContext` and render elements |
92
+
|`reference`| Required |`string`| - | The name of the resource for the referenced records, e.g. 'books' |
93
+
|`target`| Required |`string`| - | Target field carrying the relationship on the referenced resource, e.g. 'user_id' |
94
+
|`children`| Optional *|`Element`| - | One or several elements that render a list of records based on a `ListContext`|
95
+
|`render`| Optional *|`(listContext) => Element`| - | Function that receives a `ListContext` and render elements |
94
96
|`debounce`| Optional |`number`| 500 | debounce time in ms for the `setFilters` callbacks |
95
97
|`empty`| Optional |`ReactNode`| - | Element to display when there are no related records. |
96
98
|`filter`| Optional |`Object`| - | Filters to use when fetching the related records, passed to `getManyReference()`|
97
99
|`pagination`| Optional |`Element`| - | Pagination element to display pagination controls. empty by default (no pagination) |
98
100
|`perPage`| Optional |`number`| 25 | Maximum number of referenced records to fetch |
99
101
|`queryOptions`| Optional |[`UseQuery Options`](https://tanstack.com/query/v3/docs/react/reference/useQuery)|`{}`|`react-query` options for the `getMany` query |
100
-
|`reference`| Required |`string`| - | The name of the resource for the referenced records, e.g. 'books' |
101
102
|`sort`| Optional |`{ field, order }`|`{ field: 'id', order: 'DESC' }`| Sort order to use when fetching the related records, passed to `getManyReference()`|
102
103
|`source`| Optional |`string`|`id`| Target field carrying the relationship on the source record (usually 'id') |
103
104
|`storeKey`| Optional |`string`| - | The key to use to store the records selection state |
104
-
|`target`| Required |`string`| - | Target field carrying the relationship on the referenced resource, e.g. 'user_id' |
105
+
106
+
`*` You must provide either `children` or `render`.
105
107
106
108
`<ReferenceManyField>` also accepts the [common field props](./Fields.md#common-field-props), except `emptyText` (use the child `empty` prop instead).
Alternatively to children you can pass a render prop to `<ReferenceManyField>`. The render prop will receive the list context as its argument, allowing to inline the render logic for both the list and the pagination.
170
-
When receiving a render prop the `<ReferenceManyField>` component will ignore the children and the pagination property.
By default, `<ReferenceManyField>` does not refresh the data as soon as the user enters data in the filter form. Instead, it waits for half a second of user inactivity (via `lodash.debounce`) before calling the `dataProvider` on filter change. This is to prevent repeated (and useless) calls to the API.
@@ -416,6 +356,35 @@ For instance, if you want to display the `books` of a given `author`, the `refer
416
356
</ReferenceManyField>
417
357
```
418
358
359
+
## `render`
360
+
361
+
Alternatively to `children`, you can pass a `render` prop to `<ReferenceManyField>`. It will receive the [`ListContext`](./useListContext.md#return-value) as its argument, and should return a React node.
362
+
363
+
This allows to inline the render logic for the list of related records.
By default, it orders the possible values by id desc. You can change this order by setting the `sort` prop (an object with `field` and `order` properties).
0 commit comments