A hook that helps you delete multiple resources at once.

The hook uses useMutation from `@tanstack/react-query under the hood, so it accepts all the same options. It performs an optimistic update by removing the resources from the cache before the deletion requests are sent. If any deletion fails, the resources are restored in the cache.

If the undoable mode is enabled, the hook allows the deletions to be undone within a certain period of time. If the undo action is not performed, the resources will be permanently deleted.

@example import { useDeleteMany } from 'react-query-manager';

type TData = { id: 1, name: 'Test' }; const PATH = 'users/{id}/messages';

const { delete: deleteMany } = useDeleteMany<typeof PATH, TData>({ resourcePath: PATH, });

deleteMany({ ids: [123, 456], resourceParams: { id: 1 }, undoMessage: 'Messages deleted', });

@template TPath - The API path as a string. @template TData - The expected shape of the data returned by the API.

@param props - The options for the hook. @returns An object with properties, delete and mutation.

delete is a function that takes the ID and params of the resource to delete, and calls the mutation function with the necessary data.

mutation is result useMutation without propery mutate

  • Type Parameters

    • TPath extends string
    • TData = any
    • TExtraData = any

    Parameters

    Returns {
        delete: ((__namedParameters: DeleteBaseVariables<TPath, "many", TExtraData>) => Promise<void>);
        mutation:
            | {
                context: unknown;
                data: undefined;
                error: null;
                failureCount: number;
                failureReason: null | CustomError;
                isError: false;
                isIdle: true;
                isPaused: boolean;
                isPending: false;
                isSuccess: false;
                mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                }, unknown>;
                reset: (() => void);
                status: "idle";
                submittedAt: number;
                variables: undefined;
            }
            | {
                context: unknown;
                data: undefined;
                error: null;
                failureCount: number;
                failureReason: null | CustomError;
                isError: false;
                isIdle: false;
                isPaused: boolean;
                isPending: true;
                isSuccess: false;
                mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                }, unknown>;
                reset: (() => void);
                status: "pending";
                submittedAt: number;
                variables: {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                };
            }
            | {
                context: unknown;
                data: undefined;
                error: CustomError;
                failureCount: number;
                failureReason: null | CustomError;
                isError: true;
                isIdle: false;
                isPaused: boolean;
                isPending: false;
                isSuccess: false;
                mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                }, unknown>;
                reset: (() => void);
                status: "error";
                submittedAt: number;
                variables: {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                };
            }
            | {
                context: unknown;
                data: QueryResponse<TData>[];
                error: null;
                failureCount: number;
                failureReason: null | CustomError;
                isError: false;
                isIdle: false;
                isPaused: boolean;
                isPending: false;
                isSuccess: true;
                mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                }, unknown>;
                reset: (() => void);
                status: "success";
                submittedAt: number;
                variables: {
                    apiClientParams?: Partial<ApiProps>;
                    extraData?: TExtraData;
                    extraResources?: Resource<any>[];
                    ids: (string | number)[];
                    resource: Resource<TPath>;
                };
            };
    }

    • delete: ((__namedParameters: DeleteBaseVariables<TPath, "many", TExtraData>) => Promise<void>)
    • mutation:
          | {
              context: unknown;
              data: undefined;
              error: null;
              failureCount: number;
              failureReason: null | CustomError;
              isError: false;
              isIdle: true;
              isPaused: boolean;
              isPending: false;
              isSuccess: false;
              mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              }, unknown>;
              reset: (() => void);
              status: "idle";
              submittedAt: number;
              variables: undefined;
          }
          | {
              context: unknown;
              data: undefined;
              error: null;
              failureCount: number;
              failureReason: null | CustomError;
              isError: false;
              isIdle: false;
              isPaused: boolean;
              isPending: true;
              isSuccess: false;
              mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              }, unknown>;
              reset: (() => void);
              status: "pending";
              submittedAt: number;
              variables: {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              };
          }
          | {
              context: unknown;
              data: undefined;
              error: CustomError;
              failureCount: number;
              failureReason: null | CustomError;
              isError: true;
              isIdle: false;
              isPaused: boolean;
              isPending: false;
              isSuccess: false;
              mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              }, unknown>;
              reset: (() => void);
              status: "error";
              submittedAt: number;
              variables: {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              };
          }
          | {
              context: unknown;
              data: QueryResponse<TData>[];
              error: null;
              failureCount: number;
              failureReason: null | CustomError;
              isError: false;
              isIdle: false;
              isPaused: boolean;
              isPending: false;
              isSuccess: true;
              mutateAsync: UseMutateAsyncFunction<QueryResponse<TData>[], CustomError, {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              }, unknown>;
              reset: (() => void);
              status: "success";
              submittedAt: number;
              variables: {
                  apiClientParams?: Partial<ApiProps>;
                  extraData?: TExtraData;
                  extraResources?: Resource<any>[];
                  ids: (string | number)[];
                  resource: Resource<TPath>;
              };
          }