Data error
i have this mutation
mutate(
{
resource:
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?
/${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
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:
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:
----------------------<@737073867532796026> kapa.ai is still learning and improving, please let us know how it did by reacting below
optimistic-gold•6mo ago
@kapa.ai but i dont use any data on the useCreate
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:
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:
----------------------<@737073867532796026> kapa.ai is still learning and improving, please let us know how it did by reacting below