31 lines
754 B
TypeScript
31 lines
754 B
TypeScript
import { useMutation, UseMutationResult } from "react-query";
|
|
import useAxios from "./useAxios";
|
|
import { HEADER_KEY } from "../config";
|
|
import { AxiosResponse } from "../../types/Axios";
|
|
|
|
type DataToSend = {
|
|
id: number | string;
|
|
};
|
|
|
|
function useDeleteMutation(
|
|
key: any,
|
|
url: string,
|
|
toast:boolean = true
|
|
|
|
): UseMutationResult<AxiosResponse, unknown, DataToSend, unknown> {
|
|
const axios = useAxios();
|
|
return useMutation<AxiosResponse, unknown, DataToSend, unknown>(
|
|
async (dataToSend) => {
|
|
const { data } = await axios.delete(url + `/` + dataToSend?.id, {
|
|
headers: {
|
|
[HEADER_KEY]: key,
|
|
["X-Custom-Message"] : toast
|
|
},
|
|
});
|
|
return data;
|
|
},
|
|
);
|
|
}
|
|
|
|
export default useDeleteMutation;
|