Skip to content

DeleteButton

Lets the user delete the current record.

import { DeleteButton, Edit } from '@/components/admin';
const PostEdit = () => (
<Edit actions={<DeleteButton />}>
...
</Edit>
);

By default, it reads the resource from ResourceContext and record from RecordContext.

Upon success, the button redirects to the list view, and notifies the user with the key resources.<resource>.notifications.deleted (fallback ra.notification.deleted).

PropRequiredTypeDefaultDescription
classNameOptionalstringdestructive stylesAdditional classes
labelOptionalstringi18n computedi18n key / custom label (includes record name)
mutationOptionsOptionalUseDeleteOptions-Mutation options (onSuccess, etc.)
redirectOptionalRedirectionSideEffectlistWhere to redirect after delete
sizeOptional"default" | "sm" | "lg" | "icon"-Size variant
successMessageOptionalstring-Custom success i18n key
variantOptional"default" | "destructive" | "outline" | "secondary" | "ghost" | "link"outlineButton style

By default, the label is computed from the ra.action.delete translation key, which reads “Delete”.

You can customize the label for a specific resource by adding a resources.{resource}.action.delete key to your translation messages. It receives %{name} (singular resource name) and %{recordRepresentation} (string representation of the current record):

const messages = {
resources: {
posts: {
action: {
delete: 'Remove %{recordRepresentation}',
},
},
},
};

You can also pass a custom string or translation key directly via the label prop:

<DeleteButton label="Remove" />
<DeleteButton label="resources.posts.action.delete" />

If your data provider supports soft delete (see Soft Delete Features), you can use an alternative SoftDeleteButton that performs a soft delete instead of a permanent delete.

You can then choose to either restore the record with a RestoreButton, or delete it permanently with a DeletePermanentlyButton.