ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
53 lines • 1.59 kB
JavaScript
import { useDeleteController, } from "./useDeleteController.js";
import { useEvent } from "../../util/index.js";
/**
* Prepare callback for a Delete button with undo support
* @deprecated prefer the useDeleteController hook instead
* @example
*
* import React from 'react';
* import ActionDelete from '@mui/icons-material/Delete';
* import { Button, useDeleteWithUndoController } from 'react-admin';
*
* const DeleteButton = ({
* resource,
* record,
* redirect,
* onClick,
* ...rest
* }) => {
* const { isPending, handleDelete } = useDeleteWithUndoController({
* resource,
* record,
* redirect,
* onClick,
* });
*
* return (
* <Button
* onClick={handleDelete}
* disabled={isPending}
* label="ra.action.delete"
* {...rest}
* >
* <ActionDelete />
* </Button>
* );
* };
*/
const useDeleteWithUndoController = (props) => {
const { onClick } = props;
const { isPending, handleDelete: controllerHandleDelete } = useDeleteController({ ...props, mutationMode: 'undoable' });
const handleDelete = useEvent((event) => {
if (event && event.stopPropagation) {
event.stopPropagation();
}
controllerHandleDelete();
if (typeof onClick === 'function') {
onClick(event);
}
});
return { isPending, isLoading: isPending, handleDelete };
};
export default useDeleteWithUndoController;
//# sourceMappingURL=useDeleteWithUndoController.js.map