I have run to this issue when try to make a post request with React-Query useMutation in Next.js 14
My package version:
- @tanstack/react-query: 5.34
- axios: 1.6.7
Here is my code:
const { mutate, isSuccess, error } = useMutation({
mutationFn: (data: AuthType) => authApi.postRegister(data),
onError(error, variables, context) {
console.log(error)
},
})
const form = useForm<z.infer<typeof registerSchema>>({
resolver: zodResolver(registerSchema),
defaultValues: {
first_name: '',
last_name: '',
email: '',
password: '',
confirm_password: '',
},
})
const onSubmit = async (values: z.infer<typeof registerSchema>) => {
console.log('onSubmit values::: ', values)
mutate(values)
}
export const authApi = {
postRegister: async (data: AuthType) => await axiosInstance.post('/auth/register', data),
}
I’ve tried to find where the issues occurred, but I still don’t know why this error happend