so I created a server action which is working, but I’m just wondering if passing a server action in a useMutation from tanstack query a good approach?
this is my previous take on submitting form
const processForm = (values: z.infer<typeof formSchemaData>) => {
createPost(values);
setSuccess("");
setError("");
startTransition(() => {
submitForm(values).then((data) => {
setError(data.error);
setSuccess(data.success);
});
});
};
Is it this a good approach to make to use it as useMutation? I want to lessen using useState for setting loading and error
This is my approach but it’s not sending payload.
const { mutate: createPost, isPending: isPending } = useMutation({
mutationFn: async (values: Inputs) => await submitForm(values),
onError: (error) => {
console.error(error);
},
onSuccess: () => {
router.push("/");
router.refresh();
},
});
const processForm = (values: z.infer<typeof formSchemaData>) => {
createPost(values);
}