我有两个成功工作的突变。但是,当我尝试添加onSuccess和invalidateQueries时,我得到以下错误:
Property 'mutateAsync' does not exist on type '{ onSuccess: () => void; }
挂钩
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])
}
}
};
使用钩子
const {
mutateAsync: addUserContactMutation
} = useAddUserContact();
const addContactOnClickHandler = (contact: User) => {
addUserContactMutation(contact);
};
1条答案
按热度按时间sg3maiej1#
我过早地关闭了useMutation调用,因此意外地使用了逗号操作符,并仅返回了该配置对象。