documentation/versioned_docs/version-3.xx.xx/api-reference/mui/components/buttons/create.md
<CreateButton> uses Material UI <Button> component. It uses the create method from useNavigation under the hood. It can be useful to redirect the app to the create page route of resource.
:::info-tip Swizzle You can swizzle this component to customize it with the refine CLI :::
const { Create } = RefineMui;
// visible-block-start
import {
useDataGrid,
DataGrid,
GridColumns,
List,
// highlight-next-line
CreateButton,
} from "@pankod/refine-mui";
const columns: GridColumns = [
{ field: "id", headerName: "ID", type: "number" },
{ field: "title", headerName: "Title", minWidth: 400, flex: 1 },
];
const PostsList: React.FC = () => {
const { dataGridProps } = useDataGrid<IPost>();
return (
// highlight-next-line
<List headerButtons={<CreateButton />}>
<DataGrid {...dataGridProps} columns={columns} autoHeight />
</List>
);
};
interface IPost {
id: number;
title: string;
}
// visible-block-end
render(
<RefineMuiDemo
resources={[
{
name: "posts",
list: PostsList,
create: () => <Create>Rest of the page here...</Create>,
},
]}
/>,
);
resourceNameOrRouteNameIt is used to redirect the app to the /create endpoint of the given resource name. By default, the app redirects to a URL with /create defined by the name property of resource object.
const { useRouterContext } = RefineCore;
// visible-block-start
import { CreateButton } from "@pankod/refine-mui";
const MyCreateComponent = () => {
return (
<CreateButton
// highlight-next-line
resourceNameOrRouteName="categories"
/>
);
};
// visible-block-end
const CreatePage = () => {
const params = useRouterContext().useParams();
return <div>{JSON.stringify(params)}</div>;
};
render(
<RefineMuiDemo
initialRoutes={["/"]}
resources={[
{
name: "posts",
},
{
name: "categories",
create: CreatePage,
},
]}
DashboardPage={MyCreateComponent}
/>,
);
Clicking the button will trigger the create method of useNavigation and then redirect to /posts/create.
hideTextIt is used to show and not show the text of the button. When true, only the button icon is visible.
const { useRouterContext } = RefineCore;
// visible-block-start
import { CreateButton } from "@pankod/refine-mui";
const MyCreateComponent = () => {
return (
<CreateButton
// highlight-next-line
hideText={true}
/>
);
};
// visible-block-end
const CreatePage = () => {
const params = useRouterContext().useParams();
return <div>{JSON.stringify(params)}</div>;
};
render(
<RefineMuiDemo
initialRoutes={["/"]}
resources={[
{
name: "posts",
list: MyCreateComponent,
create: CreatePage,
},
]}
/>,
);
accessControlThis prop can be used to skip access control check with its enabled property or to hide the button when the user does not have the permission to access the resource with hideIfUnauthorized property. This is relevant only when an accessControlProvider is provided to <Refine/>
import { CreateButton } from "@pankod/refine-mui";
export const MyListComponent = () => {
return (
<CreateButton accessControl={{ enabled: true, hideIfUnauthorized: true }} />
);
};
:::tip External Props It also accepts all props of Material UI Button. :::