useUpdate
In the refine documentation about useUpdate, it says there is an onSuccess inside mutationOptions, but I am unable to use this method. Is there a way to execute an action only if the mutate returns a success?
I am using useUpdate as follows:
const { mutate: updateIvr } = useUpdate();
const handleSaveButton = (e: React.MouseEvent<HTMLButtonElement>) => {
const ivr = {
ivr: record.id,
ivr_tree: record.ivr_tree,
};
updateIvr({
resource: "updateIvrDev",
id: ivr.ivr,
values: ivr,
});
};
2 Replies
Hi @Silvio. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It seems like you are trying to execute an action only if the
mutate
function from useUpdate
returns a success. According to the refine documentation, you can indeed use the onSuccess
method inside mutationOptions
to handle actions after a successful mutation. However, there are some nuances to be aware of.
From the knowledge sources, it appears that the onSuccess
handler might be omitted in some cases, as seen in the GitHub issue #5888 (https://github.com/refinedev/refine/issues/5888). However, you can still achieve your goal by using the successNotification
prop or by using mutateAsync
.
Here is how you can use the successNotification
prop to execute an action after a successful mutation:
Alternatively, you can use mutateAsync
to handle the success case:
These approaches should help you execute an action only if the mutate
function returns a success.
For more details, you can refer to the refine documentation on useUpdate (https://refine.dev/docs/data/hooks/use-update/#properties) and successNotification (https://refine.dev/docs/data/hooks/use-update/#successnotification).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1233408946111385630> kapa.ai is still learning and improving, please let us know how it did by reacting below