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
|`empty`| Optional |`ReactElement`|| The component to display when the data is empty. |
90
+
|`error`| Optional |`ReactElement`|| The component to display in case of error. |
91
+
|`loading`| Optional |`ReactElement`|| The component to display while checking authorizations. |
92
+
|`render`| Required |`function`|| The function to render the data |
148
93
149
94
## `empty`
150
95
@@ -214,6 +159,61 @@ If `loading` is not provided, the render function will be called with `isPending
214
159
/>
215
160
```
216
161
162
+
## `render`
163
+
164
+
A function which will be called with the current [`ListContext`](./useListContext.md) as argument. It should return a React element.
165
+
166
+
The [`ListContext`](./useListContext.md) contains the fetched array of records under the `data` key. You can use it to render a list of records:
167
+
168
+
```jsx
169
+
<WithListContext render={({ data }) => (
170
+
<ul>
171
+
{data.map(record=> (
172
+
<li key={record.id}>{record.title}</li>
173
+
))}
174
+
</ul>
175
+
)}>
176
+
```
177
+
178
+
As a reminder, the [`ListContext`](./useListContext.md) is an object with the following properties:
179
+
180
+
```jsx
181
+
<WithListContext render={({
182
+
// fetched data
183
+
data, // an array of the list records, e.g. [{ id: 123, title: 'hello world' }, { ... }]
184
+
total, // the total number of results for the current filters, excluding pagination. Useful to build the pagination controls, e.g. 23
185
+
meta, // Additional information about the list, like facets & statistics
186
+
isPending, // boolean that is true until the data is available for the first time
187
+
isLoading, // boolean that is true until the data is fetched for the first time
188
+
isFetching, // boolean that is true while the data is being fetched, and false once the data is fetched
189
+
// pagination
190
+
page, // the current page. Starts at 1
191
+
perPage, // the number of results per page. Defaults to 25
192
+
setPage, // a callback to change the page, e.g. setPage(3)
193
+
setPerPage, // a callback to change the number of results per page, e.g. setPerPage(25)
194
+
hasPreviousPage, // boolean, true if the current page is not the first one
195
+
hasNextPage, // boolean, true if the current page is not the last one
196
+
// sorting
197
+
sort, // a sort object { field, order }, e.g. { field: 'date', order: 'DESC' }
198
+
setSort, // a callback to change the sort, e.g. setSort({ field: 'name', order: 'ASC' })
199
+
// filtering
200
+
filterValues, // a dictionary of filter values, e.g. { title: 'lorem', nationality: 'fr' }
201
+
displayedFilters, // a dictionary of the displayed filters, e.g. { title: true, nationality: true }
202
+
setFilters, // a callback to update the filters, e.g. setFilters(filters, displayedFilters)
203
+
showFilter, // a callback to show one of the filters, e.g. showFilter('title', defaultValue)
204
+
hideFilter, // a callback to hide one of the filters, e.g. hideFilter('title')
205
+
// record selection
206
+
selectedIds, // an array listing the ids of the selected rows, e.g. [123, 456]
207
+
onSelect, // callback to change the list of selected rows, e.g. onSelect([456, 789])
208
+
onToggleItem, // callback to toggle the selection of a given record based on its id, e.g. onToggleItem(456)
209
+
onUnselectItems, // callback to clear the selection, e.g. onUnselectItems();
210
+
// misc
211
+
defaultTitle, // the translated title based on the resource, e.g. 'Posts'
212
+
resource, // the resource name, deduced from the location. e.g. 'posts'
213
+
refetch, // callback for fetching the list data again
214
+
}) => ( ... )}>
215
+
```
216
+
217
217
## Availability
218
218
219
219
Whenever you use a react-admin component to fetch a list of records, react-admin stores the data in a [`ListContext`](./useListContext.md). Consequently, `<WithListContext>` works in any component that is a descendant of:
0 commit comments