Skip to main content
Version: 3.xx.xx

Edit

<Edit> provides us a layout for displaying the page. It does not contain any logic but adds extra functionalities like a <RefreshButton>.

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

Properties

canDelete and deleteButtonProps

canDelete allows us to add the delete button inside the <Edit> component. If the resource has the canDelete property, refine adds the delete button by default. If you want to customize this button you can use the deleteButtonProps property like the code below.

When clicked on, the delete button executes the useDelete method provided by the dataProvider.

Refer to the <DeleteButton> documentation for detailed usage. β†’

src/pages/posts/edit.tsx
import { usePermissions } from "@pankod/refine-core";
import { Edit } from "@pankod/refine-mui";

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

return (
<Edit
canDelete={data === "admin"}
deleteButtonProps={{ size: "small" }}
>
...
</Edit>
);
};

Refer to the usePermission documentation for detailed usage. β†’

saveButtonProps

The <Edit> component has a save button by default. If you want to customize this button you can use the saveButtonProps property like the code below.

Clicking on the save button will submit your form.

Refer to the <SaveButton> documentation for detailed usage. β†’

import { Edit } from "@pankod/refine-mui";

export const EditPage: React.FC = () => {
return <Edit saveButtonProps={{ size: "small" }}>...</Edit>;
};

actionButtons

<Edit> uses the Material UI <CardActions> component. The children of the <CardActions> component shows <SaveButton> and <DeleteButton> based on your resource definition in theresourcesproperty you pass to <Refine>. If you want to use other things instead of these buttons, you can use the actionButton property like the code below.

src/pages/posts/edit.tsx
import { Edit, Button } from "@pankod/refine-mui";

export const EditPage: React.FC = () => {
return (
<Edit
actionButtons={
<>
<Button>Custom Button 1</Button>
<Button>Custom Button 2</Button>
</>
}
>
...
</Edit>
);
};

actionButton Usage

cardProps

<Edit> uses the Material UI <Card> components so you can customize with the props of cardProps.

cardHeaderProps

<Edit> uses the Material UI <CardHeader> components so you can customize with the props of cardHeaderProps.

src/pages/posts/edit.tsx
import { Edit, Typography } from "@pankod/refine-mui";

export const EditPage: React.FC = () => {
return (
<Edit
cardHeaderProps={{
title: <Typography variant="h5">Custom Title</Typography>,
}}
>
...
</Edit>
);
};

actionButton Usage

cardContentProps

<Edit> uses the Material UI <CardContent> components so you can customize with the props of cardContentProps.

cardActionsProps

<Edit> uses the Material UI <CardActions> components so you can customize with the props of cardActionsProps.

recordItemId

The <Edit> component reads the id information from the route by default. recordItemId is used when it cannot read from the URL(when used on a custom page, modal or drawer).

src/pages/posts/edit.tsx
import { useModalForm } from "@pankod/refine-react-hook-form";
import { Drawer, Edit} from "@pankod/refine-mui";

export const PostEdit: React.FC = () => {
const editDrawerFormProps = useModalForm<ICategory>({
refineCoreProps: { action: "edit" },
});

return (
<Drawer>
<Edit
...
recordItemId="2"
>
...
</Edit>
</Drawer>
);
};

interface ICategory {
id: number;
title: string;
}
note

The <Edit> component needs the id information for the <RefreshButton> to work properly.

mutationMode

Determines which mode mutation will have while executing <DeleteButton>.

Refer to the mutation mode docs for further information. β†’

src/pages/posts/edit.tsx
import { Edit } from "@pankod/refine-mui";

export const EditPage: React.FC = () => {
return <Edit mutationMode="undoable">...</Edit>;
};

resource

The <Edit> 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 <Edit> component in a custom page, you can use the resource prop.

Refer to the custom pages documentation for detailed usage. β†’

import { Refine } from "@pankod/refine-core";
import { Edit } from "@pankod/refine-mui";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";

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

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

API Reference

Properties

PropertyDescriptionTypeDefault
canDeleteAdds a <DeleteButton>booleanIf the resource has canDelete prop it is true else false false
deleteButtonPropsAdds properties for <DeleteButton>DeleteButtonProps<DeleteButton>
saveButtonPropsAdds props for <SaveButton>{ disabled: boolean; onClick: () => void; loading: boolean; }<SaveButton>
actionButtonsPasses the props for <CardActions>React.ReactNode<SaveButton> and depending on your resource configuration (canDelete prop)
cardPropsPasses the props for <Card>CardProps<SaveButton> and depending on your resource configuration (canDelete prop)
cardHeaderPropsPasses the props for <CardHeader>CardHeaderProps
cardContentPropsPasses the props for <CardContent>CardContentProps
cardActionsPropsPasses the props for <CardActions>CardActionsProps
recordItemIdThe record id for <RefreshButton>BaseKey
mutationModeDetermines when mutations are executed "pessimistic | "optimistic | "undoable""pessimistic"*
resourceResource name for API data interactionsstringResource name that it reads from the URL.
isLoadingPasses the props for <SaveButton>booleanfalse