import { useMutation, useQueryClient } from "@tanstack/react-query"; import { updateDocument, type UpdateDocumentRequest, } from "@/services/documents"; export function useUpdateDocument() { const queryClient = useQueryClient(); return useMutation({ mutationFn: (request: UpdateDocumentRequest) => updateDocument(request), // Returning the invalidate promise makes `mutateAsync` await the refetch, // so callers see fresh data the moment `await mutate(...)` resolves // instead of a brief flash of pre-update state. onSuccess: () => queryClient.invalidateQueries({ queryKey: ["knowledge-bases"] }), }); }