24 lines
577 B
TypeScript
24 lines
577 B
TypeScript
import { useMutation, useQueryClient } from 'react-query';
|
|
import api from '../services/api';
|
|
import { Comentario } from '../types/entities';
|
|
|
|
export const useComentarios = (tarefaId: string) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
const addComentario = useMutation(
|
|
async (texto: string) => {
|
|
const response = await api.post(`/tarefas/${tarefaId}/comentarios`, { texto });
|
|
return response.data;
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries(['tarefas', tarefaId]);
|
|
}
|
|
}
|
|
);
|
|
|
|
return {
|
|
addComentario
|
|
};
|
|
};
|