import { UseMutationOptions, UseMutationResult, MutateOptions } from '@tanstack/react-query'; import { RaRecord, DeleteParams, MutationMode } from '../types'; /** * Get a callback to call the dataProvider.delete() method, the result and the loading state. * * @param {string} resource * @param {Params} params The delete parameters { id, previousData } * @param {Object} options Options object to pass to the queryClient. * May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } } * May include a mutation mode (optimistic/pessimistic/undoable), e.g. { mutationMode: 'undoable' } * * @typedef Params * @prop params.id The resource identifier, e.g. 123 * @prop params.previousData The record before the update is applied * * @returns The current mutation state. Destructure as [deleteOne, { data, error, isPending }]. * * The return value updates according to the request state: * * - initial: [deleteOne, { isPending: false, isIdle: true }] * - start: [deleteOne, { isPending: true }] * - success: [deleteOne, { data: [data from response], isPending: false, isSuccess: true }] * - error: [deleteOne, { error: [error from response], isPending: false, isError: true }] * * The deleteOne() function must be called with a resource and a parameter object: deleteOne(resource, { id, previousData, meta }, options) * * This hook uses react-query useMutation under the hood. * This means the state object contains mutate, isIdle, reset and other react-query methods. * * @see https://tanstack.com/query/v5/docs/react/reference/useMutation * * @example // set params when calling the deleteOne callback * * import { useDelete, useRecordContext } from 'react-admin'; * * const DeleteButton = () => { * const record = useRecordContext(); * const [deleteOne, { isPending, error }] = useDelete(); * const handleClick = () => { * deleteOne('likes', { id: record.id, previousData: record }) * } * if (error) { return
ERROR
; } * return