Data error

i have this mutation mutate( { resource: /${API_ROUTES.USERS.USERLIST}/${id}, values: { description: values.description, hours: values.hours, date: values.date, project: values.project, },
dataProviderName: "taskTraker" }, { onError: (error, variables, context) => { // An error occurred! console.log(error); console.log("stop 1"); }, onSuccess: (data, variables, context) => { // Let's celebrate! console.log("Let's celebrate! 2"); }, } ); and i have this error:Cannot read properties of undefined (reading 'data') what can i do?
5 Replies
kapa.ai
kapa.ai3mo ago
Hi @mauryo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided, it seems like you're using a mutation function from Refine's data hooks (like useCreate, useUpdate, useDelete, etc.). When an error occurs during the mutation, you can handle it in the onError callback as you're currently doing. However, if you want to customize the error notification that shows up when the data fetching fails, you can use the errorNotification prop. This prop allows you to customize the error notification that shows up when the data fetching fails and the mutation function calls the open function from NotificationProvider. Here's an example of how you can use it:
const { mutate } = useUpdate(); // or useCreate, useDelete, etc.

mutate({
errorNotification: (data, values, resource) => {
return {
message: `Something went wrong when getting ${data.id}`,
description: "Error",
type: "error",
};
},
});
const { mutate } = useUpdate(); // or useCreate, useDelete, etc.

mutate({
errorNotification: (data, values, resource) => {
return {
message: `Something went wrong when getting ${data.id}`,
description: "Error",
type: "error",
};
},
});
In this example, errorNotification is a function that receives the data, values, and resource as parameters and returns an object with the message, description, and type of the notification. Please note that NotificationProvider (https://refine.dev/docs/notification/notification-provider/) is required for this prop to work. If you're still having trouble, could you please provide more details about the error you're encountering? That would help in providing a more specific solution. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@737073867532796026> kapa.ai is still learning and improving, please let us know how it did by reacting below
fascinating-indigo
fascinating-indigo3mo ago
@kapa.ai but i dont use any data on the useCreate
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- If you're not using any data in the useCreate hook, you can still use the errorNotification prop to customize the error message. You can set it to a static object if you don't need to access the data, values, or resource. Here's an example:
const { mutate } = useCreate();

mutate({
errorNotification: {
message: "Something went wrong",
description: "Error",
type: "error",
},
});
const { mutate } = useCreate();

mutate({
errorNotification: {
message: "Something went wrong",
description: "Error",
type: "error",
},
});
In this example, errorNotification is a static object with the message, description, and type of the notification. Remember, by setting errorNotification to false, you can disable the notification. Please note that NotificationProvider (https://refine.dev/docs/notification/notification-provider/) is required for this prop to work. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@737073867532796026> kapa.ai is still learning and improving, please let us know how it did by reacting below