Reputation: 11
I have 2 mutations which are working successfully. However, when I try to add onSuccess and invalidateQueries. I get the following error:
Property 'mutateAsync' does not exist on type '{ onSuccess: () => void; }
hooks
export const useAddUserContact = () => {
const queryClient = useQueryClient();
return useMutation(
(user: any) => axios.post("http://localhost:4000/userContacts", user)
.then(response => response.data)
),
{
onSuccess: () => {
queryClient.invalidateQueries([userContacts.fetchUserContacts])
}
}
};
export const useDeleteUserContact = () => {
const queryClient = useQueryClient();
return useMutation(
(userId: string) => axios.delete(`http://localhost:4000/userContacts/${userId}`)
.then(response => response.data)
),
{
onSuccess: () => {
queryClient.invalidateQueries([userContacts.fetchUserContacts])
}
}
};
use of hooks
const {
mutateAsync: addUserContactMutation
} = useAddUserContact();
const addContactOnClickHandler = (contact: User) => {
addUserContactMutation(contact);
};
Upvotes: 0
Views: 446
Reputation: 11
I closed the useMutation call too early, so accidentally using the comma operator and just returning that config object.
Upvotes: 1