UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

56 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const useDeleteController_1 = require("./useDeleteController.cjs"); const util_1 = require("../../util/index.cjs"); /** * 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 } = (0, useDeleteController_1.useDeleteController)({ ...props, mutationMode: 'undoable' }); const handleDelete = (0, util_1.useEvent)((event) => { if (event && event.stopPropagation) { event.stopPropagation(); } controllerHandleDelete(); if (typeof onClick === 'function') { onClick(event); } }); return { isPending, isLoading: isPending, handleDelete }; }; exports.default = useDeleteWithUndoController; module.exports = exports.default; //# sourceMappingURL=useDeleteWithUndoController.js.map