Skip to content

Commit d94631a

Browse files
committed
Apply review suggestions
1 parent 9c0a9b5 commit d94631a

File tree

3 files changed

+11
-34
lines changed

3 files changed

+11
-34
lines changed

docs/ListIterator.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: default
33
title: "ListIterator"
4-
storybook_path: react-admin-admin--basic
4+
storybook_path: ra-core-controller-list-listiterator--using-render
55
---
66

77
# `<ListIterator>`
@@ -43,9 +43,8 @@ Here are all the props you can set on the `<AccordionForm>` component:
4343
| `data` | Optional | `RaRecord[]` | - | The records. Defaults to the `data` from the `ListContext` |
4444
| `empty` | Optional | `ReactNode` | `null` | The content to display when there is no data |
4545
| `isPending` | Optional | `boolean` | - | A boolean indicating whether the data is pending. Defaults to the `isPending` from the `ListContext` |
46-
| `pending` | Optional | `ReactNode` | `null` | The content to display while the data is loading |
46+
| `loading` | Optional | `ReactNode` | `null` | The content to display while the data is loading |
4747
| `render` | Optional | `(record: RaRecord) => ReactNode` | - | A function that returns the content to render for each record |
48-
| `resource` | Optional | `string` | - | The resource. Defaults to the `ResourceContext` |
4948
| `total` | Optional | `number` | - | The total number of records. Defaults to the `total` from the `ListContext` |
5049

5150
Additional props are passed to `react-hook-form`'s [`useForm` hook](https://react-hook-form.com/docs/useform).
@@ -148,6 +147,7 @@ const DashboardMostVisitedPosts = () => {
148147
return (
149148
<OrderedList>
150149
<ListIterator
150+
data={data}
151151
isPending={isPending}
152152
render={record => <ListItem>{record.title} - {record.views}</ListItem>}
153153
/>
@@ -158,9 +158,9 @@ const DashboardMostVisitedPosts = () => {
158158
{% endraw %}
159159

160160

161-
## `pending`
161+
## `loading`
162162

163-
To provide a custom UI while the data is loading use the `pending` prop.
163+
To provide a custom UI while the data is loading use the `loading` prop.
164164

165165
{% raw %}
166166
```jsx
@@ -171,7 +171,7 @@ const DashboardMostVisitedPosts = () => (
171171
<ListBase resource="posts" sort={{ field: 'views', order: 'DESC' }} page={1} perPage={20}>
172172
<OrderedList>
173173
<ListIterator
174-
pending={<Skeleton />}
174+
loading={<Skeleton />}
175175
render={record => <ListItem>{record.title} - {record.views}</ListItem>}
176176
/>
177177
</OrderedList>
@@ -203,27 +203,6 @@ const DashboardMostVisitedPosts = () => (
203203

204204
**Note**: You can't provide both the `children` and the `render` props. If both are provided, `<ListIterator>` will use the `render` prop.
205205

206-
## `resource`
207-
208-
Although `<ListIterator>` reads the resource from the closest [`<ResourceContext>`](./Resource.md#resource-context), you may provide it yourself when no such context is available (e.g. in a [dashboard](./Admin.md#dashboard) or a [custom page](./Admin.md#adding-custom-pages)):
209-
210-
{% raw %}
211-
```jsx
212-
import { ListBase, ListIterator } from 'react-admin';
213-
import { OrderedList, ListItem } from 'my-favorite-ui-lib';
214-
215-
const DashboardMostVisitedPosts = () => (
216-
<ListBase resource="posts" sort={{ field: 'views', order: 'DESC' }} page={1} perPage={20}>
217-
<OrderedList>
218-
<ListIterator
219-
render={record => <ListItem>{record.title} - {record.views}</ListItem>}
220-
/>
221-
</OrderedList>
222-
</ListBase>
223-
);
224-
```
225-
{% endraw %}
226-
227206
## `total`
228207

229208
Although `<ListIterator>` reads the total from the closest [`<ListContext>`](./useListContext), you may provide it yourself when no such context is available:

packages/ra-core/src/controller/list/ListIterator.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const UsingRender = ({
3939
}}
4040
>
4141
<ListIterator
42-
pending={<div>Loading...</div>}
42+
loading={<div>Loading...</div>}
4343
empty={<div>No data</div>}
4444
render={record => (
4545
<li
@@ -99,7 +99,7 @@ export const UsingChildren = ({
9999
}}
100100
>
101101
<ListIterator
102-
pending={<div>Loading...</div>}
102+
loading={<div>Loading...</div>}
103103
empty={<div>No data</div>}
104104
>
105105
<ListItem />

packages/ra-core/src/controller/list/ListIterator.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { RecordContextProvider } from '../record';
66
export const ListIterator = <RecordType extends RaRecord = any>(
77
props: ListIteratorProps<RecordType>
88
) => {
9-
const { children, empty = null, pending = null, render } = props;
9+
const { children, empty = null, loading = null, render } = props;
1010
const { data, total, isPending } =
1111
useListContextWithProps<RecordType>(props);
1212

1313
if (isPending === true) {
14-
return pending ? pending : null;
14+
return loading ? loading : null;
1515
}
1616

1717
if (data == null || data.length === 0 || total === 0) {
@@ -56,10 +56,8 @@ export const ListIterator = <RecordType extends RaRecord = any>(
5656
export interface ListIteratorProps<RecordType extends RaRecord = any> {
5757
children?: React.ReactNode;
5858
empty?: React.ReactElement;
59-
pending?: React.ReactElement;
59+
loading?: React.ReactElement;
6060
render?: (record: RecordType, index: number) => React.ReactNode;
61-
// can be injected when using the component without context
62-
resource?: string;
6361
data?: RecordType[];
6462
total?: number;
6563
isPending?: boolean;

0 commit comments

Comments
 (0)