Type Parameters
- TPath extends string
- TData = any
- TExtraData = any
Returns {
delete: ((__namedParameters: DeleteBaseVariables<TPath, "one", 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>[];
id: 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>[];
id: string | number;
resource: Resource<TPath>;
}, unknown>;
reset: (() => void);
status: "pending";
submittedAt: number;
variables: {
apiClientParams?: Partial<ApiProps>;
extraData?: TExtraData;
extraResources?: Resource<any>[];
id: 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>[];
id: string | number;
resource: Resource<TPath>;
}, unknown>;
reset: (() => void);
status: "error";
submittedAt: number;
variables: {
apiClientParams?: Partial<ApiProps>;
extraData?: TExtraData;
extraResources?: Resource<any>[];
id: 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>[];
id: string | number;
resource: Resource<TPath>;
}, unknown>;
reset: (() => void);
status: "success";
submittedAt: number;
variables: {
apiClientParams?: Partial<ApiProps>;
extraData?: TExtraData;
extraResources?: Resource<any>[];
id: string | number;
resource: Resource<TPath>;
};
};
}
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
- (__namedParameters): Promise<void>
Returns 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>[];
id: 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>[];
id: string | number;
resource: Resource<TPath>;
}, unknown>;
reset: (() => void);
status: "pending";
submittedAt: number;
variables: {
apiClientParams?: Partial<ApiProps>;
extraData?: TExtraData;
extraResources?: Resource<any>[];
id: 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>[];
id: string | number;
resource: Resource<TPath>;
}, unknown>;
reset: (() => void);
status: "error";
submittedAt: number;
variables: {
apiClientParams?: Partial<ApiProps>;
extraData?: TExtraData;
extraResources?: Resource<any>[];
id: 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>[];
id: string | number;
resource: Resource<TPath>;
}, unknown>;
reset: (() => void);
status: "success";
submittedAt: number;
variables: {
apiClientParams?: Partial<ApiProps>;
extraData?: TExtraData;
extraResources?: Resource<any>[];
id: string | number;
resource: Resource<TPath>;
};
}
A hook that helps you delete a single resource.
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 resource from the cache before the deletion request is sent. If the deletion fails, the resource is restored in the cache.If the
undoable
mode is enabled, the hook allows the deletion to be undone within a certain period of time. If the undo action is not performed, the resource will be permanently deleted.Example