I use react-query in combination with react-hook-form. In order to activate the isSubmitting prop on form and show loading state while submitting, the mutate function needs to return a Promise instead of using mutate directly.
For now my workaround is as follows:
const { mutate } = useMutation(...);
const update = (data) => {
return new Promise((resolve, reject) => {
mutate(data, {
onSuccess: resolve,
onError: reject,
});
});
};
and then pass update to methods.handleSubmit comming from form.
Could anyone share some experience on this topic? Thanks!