Files
advx/src/hooks/useSubtarefas.ts
T
2025-04-10 23:07:21 -03:00

24 lines
629 B
TypeScript

import { useMutation, useQueryClient } from 'react-query';
import api from '../services/api';
import { SubTarefa } from '../types/entities';
export const useSubtarefas = (tarefaId: string) => {
const queryClient = useQueryClient();
const toggleSubtarefa = useMutation(
async ({ id, concluida }: { id: string; concluida: boolean }) => {
const response = await api.patch(`/tarefas/${tarefaId}/subtarefas/${id}`, { concluida });
return response.data;
},
{
onSuccess: () => {
queryClient.invalidateQueries(['tarefas', tarefaId]);
}
}
);
return {
toggleSubtarefa
};
};