absent-sapphire
absent-sapphire10mo ago

handleOnFinish()

const handleOnFinish = (values) => { const { ...rest } = values; onFinish({ ...rest, status: "A", }); }; How can I check if the onFinish function sent data successfully or failed?
2 Replies
kapa.ai
kapa.ai10mo ago
Hi @hoaanhtuc. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Refine, you can check if the onFinish function sent data successfully or failed by using the onSuccess and onError functions. These functions are called depending on the response status from the server. Here's an example of how you can use them:
const { onFinish, mutationResult } = useForm({
onFinish: async (values) => {
const { ...rest } = values;
await onFinish({
...rest,
status: "A",
});
},
onSuccess: (response) => {
console.log("Success response:", response);
},
onError: (error) => {
console.log("Error response:", error);
},
});
const { onFinish, mutationResult } = useForm({
onFinish: async (values) => {
const { ...rest } = values;
await onFinish({
...rest,
status: "A",
});
},
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, you can refer to this source (https://discord.com/channels/837692625737613362/1112583949735174154). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai10mo ago
<@617879699363725341> kapa.ai is still learning and improving, please let us know how it did by reacting below