Skip to content

Commit 62abeea

Browse files
committed
Document new WithListContext keys
1 parent f847200 commit 62abeea

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

docs/WithListContext.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ Whether you use `<WithListContext>` or `useListContext` is a matter of coding st
8484

8585
`<WithListContext>` accepts a single `render` prop, which should be a function.
8686

87+
| Prop | Required | Type | Default | Description |
88+
|------------|----------|----------------|---------|---------------------------------------------------------|
89+
| `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+
8794
## `render`
8895

8996
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
139146
}) => ( ... )}>
140147
```
141148

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>Error while 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+
142211
## Availability
143212

144213
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

Comments
 (0)