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 |
93
+
87
94
## `render`
88
95
89
96
A function which will be called with the current [`ListContext`](./useListContext.md) as argument. It should return a React element.
@@ -139,6 +146,68 @@ As a reminder, the [`ListContext`](./useListContext.md) is an object with the fo
139
146
}) => ( ... )}>
140
147
```
141
148
149
+
## `empty`
150
+
151
+
Use `empty` to display a dedicated component when the related record is empty.
152
+
153
+
```jsx
154
+
<WithListContext
155
+
empty={<p>no books</p>}
156
+
render={({ data }) => (
157
+
<ul>
158
+
{data.map(book=> (
159
+
<li key={book.id}>
160
+
<i>{book.title}</i>, published on
161
+
{book.published_at}
162
+
</li>
163
+
))}
164
+
</ul>
165
+
)}
166
+
loading={<p>Loading...</p>}
167
+
/>
168
+
```
169
+
170
+
## `error`
171
+
172
+
Use `error` to display a dedicated component when an error is thrown.
173
+
174
+
```jsx
175
+
<WithListContext
176
+
error={<p>Errorwhile loading books...</p>}
177
+
render={({ data }) => (
178
+
<ul>
179
+
{data.map(book=> (
180
+
<li key={book.id}>
181
+
<i>{book.title}</i>, published on
182
+
{book.published_at}
183
+
</li>
184
+
))}
185
+
</ul>
186
+
)}
187
+
loading={<p>Loading...</p>}
188
+
/>
189
+
```
190
+
191
+
## `loading`
192
+
193
+
Use `loading` to display a dedicated component while checking for users' permissions.
194
+
195
+
```jsx
196
+
<WithListContext
197
+
loading={<p>loading...</p>}
198
+
render={({ data }) => (
199
+
<ul>
200
+
{data.map(book=> (
201
+
<li key={book.id}>
202
+
<i>{book.title}</i>, published on
203
+
{book.published_at}
204
+
</li>
205
+
))}
206
+
</ul>
207
+
)}
208
+
/>
209
+
```
210
+
142
211
## Availability
143
212
144
213
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