Skip to content

Commit ef70578

Browse files
committed
Improve ListBase doc
1 parent ab82156 commit ef70578

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

docs/ListBase.md

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,81 @@ storybook_path: ra-core-controller-list-listbase--no-auth-provider
66

77
# `<ListBase>`
88

9-
`<ListBase>` is a headless variant of [`<List>`](./List.md). It fetches a list of records from the data provider, puts it in a [`ListContext`](./useListContext.md), and renders its children. Use it to build a custom list layout.
9+
`<ListBase>` is a headless List page component. It fetches a list of records from the data provider, puts it in a [`ListContext`](./useListContext.md), and renders its children. Use it to build a custom list layout.
1010

1111
Contrary to [`<List>`](./List.md), it does not render the page layout, so no title, no actions, no `<Card>`, and no pagination.
1212

1313
`<ListBase>` relies on the [`useListController`](./useListController.md) hook.
1414

1515
## Usage
1616

17-
You can use `ListBase` to create your own custom reusable List component, like this one:
17+
You can use `ListBase` to create your own custom List page component, like this one:
1818

1919
```jsx
2020
import {
21+
DataTable,
2122
ListBase,
22-
Title,
2323
ListToolbar,
24-
Pagination,
2524
DataTable,
25+
Pagination,
26+
Title,
2627
} from 'react-admin';
2728
import { Card } from '@mui/material';
2829

29-
const MyList = ({ children, actions, filters, title, ...props }) => (
30-
<ListBase {...props}>
31-
<Title title={title}/>
30+
const PostList = () => (
31+
<ListBase>
32+
<Title title="Post List"/>
3233
<ListToolbar
33-
filters={filters}
34-
actions={actions}
34+
filters={[
35+
{ source: 'q', label: 'Search', alwaysOn: true },
36+
{ source: 'published', label: 'Published', type: 'boolean' },
37+
]}
3538
/>
3639
<Card>
37-
{children}
40+
<DataTable>
41+
<DataTable.Col source="title" />
42+
<DataTable.Col source="author" />
43+
<DataTable.Col source="published_at" />
44+
</DataTable>
3845
</Card>
3946
<Pagination />
4047
</ListBase>
4148
);
49+
```
4250

51+
Alternatively, you can pass a `render` function prop instead of `children`. This function will receive the `ListContext` as argument.
52+
53+
```jsx
4354
const PostList = () => (
44-
<MyList title="Post List">
45-
<DataTable>
46-
...
47-
</DataTable>
48-
</MyList>
55+
<ListBase render={({ data, total, isPending, error }) => (
56+
<Card>
57+
<Title title="Post List" />
58+
<ListToolbar
59+
filters={[
60+
{ source: 'q', label: 'Search', alwaysOn: true },
61+
{ source: 'published', label: 'Published', type: 'boolean' },
62+
]}
63+
/>
64+
<DataTable>
65+
{data?.map(record => (
66+
<DataTable.Row key={record.id}>
67+
<DataTable.Col source="title" record={record} />
68+
<DataTable.Col source="author" record={record} />
69+
<DataTable.Col source="published_at" record={record} />
70+
</DataTable.Row>
71+
))}
72+
</DataTable>
73+
<Pagination total={total} />
74+
</Card>
75+
)} />
4976
);
5077
```
5178
52-
This custom List component has no aside component - it's up to you to add it in pure React.
53-
5479
## Props
5580
56-
The `<ListBase>` component accepts the same props as [`useListController`](./useListController.md):
81+
The `<ListBase>` component accepts the following props:
5782
83+
* `children`
5884
* [`debounce`](./List.md#debounce)
5985
* [`disableAuthentication`](./List.md#disableauthentication)
6086
* [`disableSyncWithLocation`](./List.md#disablesyncwithlocation)
@@ -63,11 +89,12 @@ The `<ListBase>` component accepts the same props as [`useListController`](./use
6389
* [`filterDefaultValues`](./List.md#filterdefaultvalues)
6490
* [`perPage`](./List.md#perpage)
6591
* [`queryOptions`](./List.md#queryoptions)
92+
* `render`
6693
* [`resource`](./List.md#resource)
6794
* [`sort`](./List.md#sort)
6895
6996
In addition, `<ListBase>` renders its children components inside a `ListContext`. Check [the `<List children>` documentation](./List.md#children) for usage examples.
70-
Alternatively, you can pass a `render` function prop instead of `children`. This function will receive the `ListContext` as argument.
97+
7198
7299
## Security
73100

0 commit comments

Comments
 (0)