import { UseMutationOptions, UseMutationResult, MutateOptions } from '@tanstack/react-query'; import { RaRecord, DeleteManyParams, 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 { ids } * @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.ids The resource identifiers, e.g. [123, 456] * * @returns The current mutation state. Destructure as [deleteMany, { data, error, isPending }]. * * The return value updates according to the request state: * * - initial: [deleteMany, { isPending: false, isIdle: true }] * - start: [deleteMany, { isPending: true }] * - success: [deleteMany, { data: [data from response], isPending: false, isSuccess: true }] * - error: [deleteMany, { error: [error from response], isPending: false, isError: true }] * * The deleteMany() function must be called with a resource and a parameter object: deleteMany(resource, { ids, 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 deleteMany callback * * import { useDeleteMany } from 'react-admin'; * * const BulkDeletePostsButton = ({ selectedIds }) => { * const [deleteMany, { isPending, error }] = useDeleteMany(); * const handleClick = () => { * deleteMany('posts', { ids: selectedIds }) * } * if (error) { return

ERROR

; } * return ; * }; * * @example // set params when calling the hook * * import { useDeleteMany } from 'react-admin'; * * const BulkDeletePostsButton = ({ selectedIds }) => { * const [deleteMany, { isPending, error }] = useDeleteMany('posts', { ids: selectedIds }); * const handleClick = () => { * deleteMany() * } * if (error) { return

ERROR

; } * return ; * }; * * @example // TypeScript * const [deleteMany, { data }] = useDeleteMany('products', { ids }); * \-- data is Product */ export declare const useDeleteMany: (resource?: string, params?: Partial>, options?: UseDeleteManyOptions) => UseDeleteManyResult; export interface UseDeleteManyMutateParams { resource?: string; ids?: RecordType['id'][]; meta?: any; } export type UseDeleteManyOptions = UseMutationOptions>> & { mutationMode?: MutationMode; }; export type UseDeleteManyResult = [ (resource?: string, params?: Partial>, options?: MutateOptions>, unknown> & { mutationMode?: MutationMode; }) => Promise, UseMutationResult & { resource?: string; }>, unknown> & { isLoading: boolean; } ]; //# sourceMappingURL=useDeleteMany.d.ts.map