Delete
<DeleteButton>
uses Chakra UI's <Button>
and <Popover>
components.
When you try to delete something, a pop-up shows up and asks for confirmation. When confirmed it executes the useDelete
method provided by your dataProvider
.
You can swizzle this component to customize it with the Refine CLI
Usage
Properties
recordItemId
recordItemId
allows us to manage which record will be deleted. By default, it will be read from the URL.
Clicking the button will trigger the useDelete
method and then the record whose resource is "post" and whose id is "123" gets deleted.
resource
resource
allows us to manage which resource's record is going to be deleted. By default, it will be read from the URL.
Clicking the button will trigger the useDelete
method and then the record whose resource is "categories" and whose id is "2" gets deleted.
If you have multiple resources with the same name, you can pass the identifier
instead of the name
of the resource. It will only be used as the main matching key for the resource, data provider methods will still work with the name
of the resource defined in the <Refine/>
component.
For more information, refer to the
identifier
section of the<Refine/>
component documentation →
onSuccess
onSuccess
can be used if you want to do anything based on the result returned after the delete request.
For example, let's console.log
after deletion:
mutationMode
Determines which mode mutation will have while executing <DeleteButton>
.
For more information, refer to the mutation mode docsumentation →
hideText
hideText
is used to show and not show the text of the button. When true
, only the button icon is visible.
accessControl
The accessControl
prop can be used to skip the 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 { DeleteButton } from "@refinedev/chakra-ui";
export const MyListComponent = () => {
return (
<DeleteButton accessControl={{ enabled: true, hideIfUnauthorized: true }} />
);
};
resourceNameOrRouteName deprecated
Use resource
prop instead.
How to override confirm texts?
You can change the text that appears when you confirm a transaction with confirmTitle
prop, as well as what 'ok' and 'cancel' buttons text look like with the confirmOkText
and confirmCancelText
props.
API Reference
Properties
Property | Type | Description | Default |
---|---|---|---|
meta |
| Additional meta data to pass to the delete mutation from the data provider | |
resource |
| Resource name for API data interactions. | Inferred resource name from the route |
hideText |
| Whether should hide the text and show only the icon or not. |
|
resourceNameOrRouteName Please use |
| Resource name for API data interactions | Reads |
accessControl |
| Access Control configuration for the button |
|
svgIconProps |
| ||
recordItemId | Data item identifier for the actions with the API | Reads | |
successNotification |
| Success notification configuration to be displayed when the mutation is successful. | '"There was an error creating resource (status code: |
errorNotification |
| Error notification configuration to be displayed when the mutation fails. | '"There was an error creating resource (status code: |
onSuccess |
| Callback function to be called after the delete action is successful | |
mutationMode |
| Mutation mode for the delete action |
|
metaData
|
| Additional meta data to pass to the delete mutation from the data provider | |
dataProviderName |
| Target data provider name for API call to be made |
|
confirmTitle |
| Text to be displayed in the confirmation popup |
|
confirmOkText |
| Confirmation button text to be displayed in the confirmation popup |
|
confirmCancelText |
| Cancel button text to be displayed in the confirmation popup |
|
invalidates |
| Query keys to be invalidated after the delete action is successful |
|