Custom delete mutation
Is there a way to specify what mutation is executed when clicking on the DeleteButton. I want to have custom delete logic on the backend.
<DeleteButton /> in refine. The useDelete hook, which is used internally by the <DeleteButton />, allows you to customize the mutation logic.useDelete hook to implement custom delete logic:mutate function from useDelete is called with custom parameters, including resource, id, mutationMode, onSuccess, and onError. This allows you to define custom logic for handling the delete operation.<DeleteButton /> component directly but still need custom logic, you can override the onConfirm prop of the <Popconfirm /> component used internally by <DeleteButton />. However, this approach requires more in-depth customization and understanding of the internal implementation of the <DeleteButton />.<DeleteButton /> works internally, you can refer to the refine blog post (https://refine.dev/blog/refine-react-invoice-generator-4/#refine-ant-design-deletebutton-).<DeleteButton /><DeleteButton /><DeleteButton /><DeleteButton /><DeleteButton /><DeleteButton />useDeleteuseDeleteuseDeleteresourcemutationModeonConfirm<Popconfirm />import { useDelete } from "@refinedev/core";
import { Button } from "@refinedev/antd"; // or "@refinedev/mui", "@refinedev/chakra-ui", "@refinedev/mantine" based on your UI framework
const CustomDeleteButton = ({ recordItemId }) => {
const { mutate } = useDelete();
const handleDelete = () => {
mutate({
resource: "your-resource-name",
id: recordItemId,
mutationMode: "undoable", // or "pessimistic", "optimistic"
onSuccess: (response) => {
// Custom success logic
console.log("Delete successful", response);
},
onError: (error) => {
// Custom error logic
console.error("Delete failed", error);
},
});
};
return <Button onClick={handleDelete}>Delete</Button>;
};
export default CustomDeleteButton;