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
By default, `<ReferenceArrayFieldBase>` renders its children even when the related records list is empty. You can customize what is rendered by providing your own component via the `empty` prop:
You can also have `<ReferenceArrayFieldBase>` render nothing in that case by setting the prop to `null`:
156
+
157
+
```jsx
158
+
<ReferenceArrayFieldBase
159
+
source="tag_ids"
160
+
reference="tags"
161
+
empty={null}
162
+
>
163
+
...
164
+
</ReferenceArrayFieldBase>
165
+
```
166
+
167
+
## `error`
168
+
169
+
By default, `<ReferenceArrayFieldBase>` renders its children even when an error occurs while fetching the related records. You can customize what is rendered by providing your own component via the `error` prop:
You can also have `<ReferenceArrayFieldBase>` render nothing in that case by setting the prop to `null`:
188
+
189
+
```jsx
190
+
<ReferenceArrayFieldBase
191
+
source="tag_ids"
192
+
reference="tags"
193
+
error={null}
194
+
>
195
+
...
196
+
</ReferenceArrayFieldBase>
197
+
```
198
+
132
199
## `render`
133
200
134
201
Alternatively to `children`, you can pass a `render` function prop to `<ReferenceArrayFieldBase>`. The `render` prop will receive the `ListContext` as its argument, allowing to inline the rendering logic.
@@ -176,12 +243,44 @@ For instance, to render only tags that are 'published', you can use the followin
176
243
```
177
244
{% endraw %}
178
245
246
+
## `loading`
247
+
248
+
By default, `<ReferenceArrayFieldBase>` renders its children even while fetching the related records. You can customize what is rendered by providing your own component via the `loading` prop:
You can also have `<ReferenceArrayFieldBase>` render nothing in that case by setting the prop to `null`:
267
+
268
+
```jsx
269
+
<ReferenceArrayFieldBase
270
+
source="tag_ids"
271
+
reference="tags"
272
+
loading={null}
273
+
>
274
+
...
275
+
</ReferenceArrayFieldBase>
276
+
```
277
+
179
278
## `offline`
180
279
181
280
By default, `<ReferenceArrayFieldBase>` renders nothing when there is no connectivity and the records haven't been cached yet. You can provide your own component via the `offline` prop:
**Tip**: If the records are in the Tanstack Query cache but you want to warn the user that they may see an outdated version, you can use the `<IsOffline>` component:
| `children` | Optional | `Element` | - | One or several elements that render a list of records based on a `ListContext` |
92
+
| `children` | Optional\* | `Element` | - | One or several elements that render a list of records based on a `ListContext` |
93
93
| `render` | Optional\* | `(ListContext) =>Element` | - | Function that receives a `ListContext` and returns an element |
94
-
| `debounce` | Optional\* | `number` | 500 | debounce time in ms for the `setFilters` callbacks |
94
+
| `debounce` | Optional | `number` | 500 | debounce time in ms for the `setFilters` callbacks |
95
95
| `empty` | Optional | `ReactNode` | - | Element to display when there are no related records. |
96
+
| `error` | Optional | `ReactNode` | - | The component to render when an error occurs while fetching the related records |
96
97
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records, passed to `getManyReference()` |
98
+
| `loading` | Optional | `ReactNode` | - | The component to render while fetching the related records |
97
99
| `offline` | Optional | `ReactNode` | - | Element to display when there are no related records because of lack of network connectivity. |
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 |
@@ -177,6 +179,38 @@ Use `empty` to customize the text displayed when there are no related records.
177
179
</ReferenceManyFieldBase>
178
180
```
179
181
182
+
## `error`
183
+
184
+
By default, `<ReferenceManyFieldBase>` 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:
You can also have `<ReferenceManyFieldBase>` render nothing in that case by setting the prop to `null`:
203
+
204
+
```jsx
205
+
<ReferenceManyFieldBase
206
+
reference="books"
207
+
target="author_id"
208
+
error={null}
209
+
>
210
+
...
211
+
</ReferenceManyFieldBase>
212
+
```
213
+
180
214
## `filter`: Permanent Filter
181
215
182
216
You can filter the query used to populate the possible values. Use the `filter` prop for that.
@@ -195,6 +229,38 @@ You can filter the query used to populate the possible values. Use the `filter`
195
229
196
230
{% endraw %}
197
231
232
+
## `loading`
233
+
234
+
By default, `<ReferenceManyFieldBase>` renders its children while fetching the related records. You can customize what is rendered by providing your own component via the `loading` prop:
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/ReferenceArrayFieldBase.md
+100-1Lines changed: 100 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,11 +87,14 @@ You can change how the list of related records is rendered by passing a custom c
87
87
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'tags' |
88
88
| `children` | Optional\* | `Element` | | One or several elements that render a list of records based on a `ListContext` |
89
89
| `render` | Optional\* | `(ListContext) =>Element` | | A function that takes a list context and renders 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 |
90
92
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records (the filtering is done client-side) |
93
+
| `loading` | Optional | `ReactNode` | - | The component to render while fetching the related records |
91
94
| `perPage` | Optional | `number` | 1000 | Maximum number of results to display |
92
95
| `queryOptions` | Optional | [`UseQuery Options`](https://tanstack.com/query/v5/docs/react/reference/useQuery) | `{}` | `react-query` options for the `getMany` query |
93
96
| `sort` | Optional | `{ field, order }` | `{ field:'id', order:'DESC' }` | Sort order to use when displaying the related records (the sort is done client-side) |
94
-
| `sortBy` | Optional | `string |Function` | `source` | When used in a `List`, name of the field to use for sorting when the user clicks on the column header. |
97
+
| `sortBy` | Optional | `string \|Function` | `source` | When used in a `List`, name of the field to use for sorting when the user clicks on the column header. |
By default, `<ReferenceArrayFieldBase>` 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:
You can also have `<ReferenceArrayFieldBase>` render nothing in that case by setting the prop to `null`:
151
+
152
+
```jsx
153
+
<ReferenceArrayFieldBase
154
+
source="tag_ids"
155
+
reference="tags"
156
+
empty={null}
157
+
>
158
+
...
159
+
</ReferenceArrayFieldBase>
160
+
```
161
+
162
+
## `error`
163
+
164
+
By default, `<ReferenceArrayFieldBase>` 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:
You can also have `<ReferenceArrayFieldBase>` render nothing in that case by setting the prop to `null`:
183
+
184
+
```jsx
185
+
<ReferenceArrayFieldBase
186
+
source="tag_ids"
187
+
reference="tags"
188
+
error={null}
189
+
>
190
+
...
191
+
</ReferenceArrayFieldBase>
192
+
```
193
+
127
194
## `render`
128
195
129
196
Alternatively to `children`, you can pass a `render` function prop to `<ReferenceArrayFieldBase>`. The `render` prop will receive the `ListContext` as its argument, allowing to inline the rendering logic.
@@ -169,6 +236,38 @@ For instance, to render only tags that are 'published', you can use the followin
169
236
/>
170
237
```
171
238
239
+
## `loading`
240
+
241
+
By default, `<ReferenceArrayFieldBase>` renders its children while fetching the related records. You can customize what is rendered by providing your own component via the `loading` prop:
You can also have `<ReferenceArrayFieldBase>` render nothing in that case by setting the prop to `null`:
260
+
261
+
```jsx
262
+
<ReferenceArrayFieldBase
263
+
source="tag_ids"
264
+
reference="tags"
265
+
loading={null}
266
+
>
267
+
...
268
+
</ReferenceArrayFieldBase>
269
+
```
270
+
172
271
## `perPage`
173
272
174
273
`<ReferenceArrayFieldBase>` fetches *all* the related fields, and puts them all in a `ListContext`. If a record has a large number of related records, it may be a good idea to limit the number of displayed records. The `perPage` prop allows to create a client-side pagination for the related records.
0 commit comments