🚨 문제 상황
import {useMutation, useQueryClient} from '@tanstack/react-query';
import {deleteMedication} from '@/apis/medication/deleteMedication';
export const useDeleteMedication = () => {
const queryClient = useQueryClient();
return useMutation<void, Error, string>({
mutationFn: deleteMedication,
onSuccess: () => {
queryClient.invalidateQueries(['medicationList']);
},
onError: (error: Error) => {
console.error('Error deleting medication:', error);
},
});
};
- queryClient.invalidateQueries(['medicationList']);
- 이 부분에서 에러가 났다
🥁 해결 방법
import {useMutation, useQueryClient} from '@tanstack/react-query';
import {deleteMedication} from '@/apis/medication/deleteMedication';
export const useDeleteMedication = () => {
const queryClient = useQueryClient();
return useMutation<void, Error, string>({
mutationFn: deleteMedication,
onSuccess: () => {
queryClient.invalidateQueries({queryKey: ['medicationList']});
},
onError: (error: Error) => {
console.error('Error deleting medication:', error);
},
});
};
- queryClient.invalidateQueries({queryKey: ['medicationList']});
- 이렇게 고치니 해결되었다
깃허브 토론을 보면 버전 차이인 것 같다!
반응형