R
Refine

ask-any-question

Confirmation on mutate update

Eeastern-cyan3/25/2024
How can i add Confirmation on mutate update for useUpdate
Kkapa.ai3/25/2024
Hi @Joe Gaffney. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The useUpdate hook in Refine does not directly support a confirmation mechanism. However, you can implement a confirmation step before calling the mutate function from useUpdate. Here's a basic example:
import { useUpdate } from "@refinedev/core";

const { mutate } = useUpdate();

const handleUpdate = (data) => {
if (window.confirm("Are you sure you want to update this data?")) {
mutate(data);
}
};
import { useUpdate } from "@refinedev/core";

const { mutate } = useUpdate();

const handleUpdate = (data) => {
if (window.confirm("Are you sure you want to update this data?")) {
mutate(data);
}
};
In this example, handleUpdate is a function that shows a confirmation dialog. If the user confirms, it calls mutate with the provided data. Remember that the useUpdate hook also provides successNotification and errorNotification props that allow you to customize the notifications shown when the update operation is successful or fails. You need to have NotificationProvider for these props to work. Here's an example of how you can use these props:
const { mutate } = useUpdate();

mutate({
successNotification: (data, values, resource) => {
return {
message: `${data.title} Successfully fetched.`,
description: "Success with no errors",
type: "success",
};
},
errorNotification: (data, values, resource) => {
return {
message: `Something went wrong when getting ${data.id}`,
description: "Error",
type: "error",
};
},
});
const { mutate } = useUpdate();

mutate({
successNotification: (data, values, resource) => {
return {
message: `${data.title} Successfully fetched.`,
description: "Success with no errors",
type: "success",
};
},
errorNotification: (data, values, resource) => {
return {
message: `Something went wrong when getting ${data.id}`,
description: "Error",
type: "error",
};
},
});
For more information, you can check the useUpdate documentation (https://refine.dev/docs/data/hooks/use-update/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Kkapa.ai3/25/2024
<@422289470487003153> kapa.ai is still learning and improving, please let us know how it did by reacting below

Looking for more? Join the community!

R
Refine

ask-any-question

Join Server