Skip to content

Commit

Permalink
fix: 뮤테이션 메서드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
a-honey committed Feb 21, 2024
1 parent 444a5c9 commit 73732ba
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/hooks/queries/useBaseMutation.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import axiosInstance from '@/api/axiosInstance';
import { useMutation } from '@tanstack/react-query';

export const fetchData = async <T>(url: string, body: T) => {
const response = await axiosInstance.post<{ data: T }>(url, body);
export const fetchData = async <T>(url: string, body: T, method: string) => {
const response = await axiosInstance.request({
method,
url,
data: body,
});

return response.data;
};

export const useBaseMutation = <T>(
mutationKey: any,
url: string,
onSuccess: (any: any) => void,
method: 'POST' | 'PUT' | 'DELETE' = 'POST',
) => {
return useMutation({
mutationKey,
mutationFn: async (body: T) => {
const response = await fetchData<T>(url, body);
const response = await fetchData<T>(url, body, method);

onSuccess(response.data);
},
Expand Down

0 comments on commit 73732ba

Please sign in to comment.