rising-crimson
rising-crimson15mo ago

useForm onFinish response

hi how I can get the response from the back end with inFinish example:
const response = await onFinish({
...data,
products: tableData,
finalPrice: finalPrice,
});
const response = await onFinish({
...data,
products: tableData,
finalPrice: finalPrice,
});
Thanks
3 Replies
kapa.ai
kapa.ai15mo ago
Hi @Deleted User. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, the onFinish function is used to trigger the mutation and handle the form submission. To get the response from the backend, you can use the onSuccess or onError functions, which are called depending on the response status. Here's an example:
const { onFinish, mutationResult } = useForm({
onFinish: async (values) => {
// Your custom logic before submitting the form
const data = {
...values,
products: tableData,
finalPrice: finalPrice,
};

await onFinish(data);
},
onSuccess: (response) => {
console.log("Success response:", response);
},
onError: (error) => {
console.log("Error response:", error);
},
});
const { onFinish, mutationResult } = useForm({
onFinish: async (values) => {
// Your custom logic before submitting the form
const data = {
...values,
products: tableData,
finalPrice: finalPrice,
};

await onFinish(data);
},
onSuccess: (response) => {
console.log("Success response:", response);
},
onError: (error) => {
console.log("Error response:", error);
},
});
In this example, the onSuccess function will be called with the successful response, and the onError function will be called with the error response. You can access the mutation result using the mutationResult returned by the useForm hook. For more information, refer to the useForm documentation (https://refine.dev/docs/api-reference/core/hooks/useForm). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai15mo ago
<@1073419683014922323> kapa.ai is still learning and improving, please let us how it did by reacting below
painful-plum
painful-plum15mo ago