Skip to main content
Version: 2.xx.xx

List

<List> provides us a layout to display the page. It does not contain any logic but adds extra functionalities like a create button or giving the page titles.

We will show what <List> does using properties with examples.

Properties

canCreate and createButtonProps

canCreate allows us to add the create button inside the <List> component. If resource is passed a create component, refine adds the create button by default. If you want to customize this button you can use createButtonProps property like the code below.

Create button redirects to the create page of the resource according to the value it reads from the URL.

import { List, usePermissions } from "@pankod/refine";

export const ListPage: React.FC = () => {
const { data } = usePermissions<string>();

return (
<List
canCreate={data === "admin"}
createButtonProps={{ size: "small" }}
>
...
</List>
);
};

Refer to the usePermission documentation for detailed usage.

title

It allows adding a title for the <List> component. if you don't pass title props, it uses plural from of resource name by default.

import { List } from "@pankod/refine";

export const ListPage: React.FC = () => {
return <List title="Custom Title">...</List>;
};

pageHeaderProps

<List> uses ant-design <PageHeader> components so you can customize with the props of pageHeaderProps.

Refer to the <PageHeader> documentation for detailed usage.

import { List } from "@pankod/refine";

export const ListPage: React.FC = () => {
return (
<List
pageHeaderProps={{
onBack: () => console.log("clicked"),
subTitle: "Subtitle",
}}
>
...
</List>
);
};

pageHeaderProps Usage

resource

<List> component reads the resource information from the route by default. This default behavior will not work on custom pages. If you want to use the <List> component in a custom page, you can use the resource prop.

Refer to the custom pages documentation for detailed usage.

import { Refine, List } from "@pankod/refine";
import routerProvider from "@pankod/refine-react-router";
import dataProvider from "@pankod/refine-simple-rest";

const CustomPage = () => {
return <List resource="posts">...</List>;
};

export const App: React.FC = () => {
return (
<Refine
routerProvider={{
...routerProvider,
routes: [
{
exact: true,
component: CustomPage,
path: "/custom",
},
]
}}
dataProvider={dataProvider("https://api.fake-rest.refine.dev/")}
resources={[{ name: "posts" }]}
/>
);
};

API Reference

Properties

PropertyDescriptionTypeDefault
canCreateAdds create buttonbooleanIf the resource is passed a create component, true else false
createButtonPropsAdds props for create buttonButtonProps & { resourceName: string }<CreateButton />
titleAdds titlestringPlural of resource.name
pageHeaderPropsPasses properties for <PageHeader>PageHeaderProps{ ghost: false, title, extra: <CreateButton /> }
resourceResource name for API data interactionsstringResource name that it reads from the url.