notification
hi
when we do post request and add something for example we will get response from the back end 200 which is ok or 404 which is bad response
in general we return message with the back end response
is there a way to present the message in the notificationProvider ?
6 Replies
Hi @Deleted User. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, refine provides a way to present messages in the
NotificationProvider
using the errorNotification
and successNotification
properties in various hooks. These properties allow you to customize the notification message based on the response from the backend.
For instance, if you're using the useOne
hook and you want to show a success notification when data is fetched successfully, you can do so like this:
In this example, ${data.title} Successfully fetched.
will be the message shown in the notification. You can customize this message based on your needs.
Similarly, if you want to show an error notification when data fetching fails, you can do so like this:
In this example, Something went wrong when getting ${data.id}
will be the message shown in the notification. Again, you can customize this message based on your needs.
These properties are available in several hooks, including useOne
, useMany
, useAutocomplete
, useShow
, and useUpdateMany
. You can find more details in the refine documentation (https://refine.dev/docs).
Please note that the NotificationProvider
is required for these properties to work.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@1073419683014922323> kapa.ai is still learning and improving, please let us how it did by reacting below
mute-gold•16mo ago
@kapa.ai
NOTE: I use old version of refine
Let me check the knowledge base for you. One moment! :books:
----------------------
In older versions of refine, you can use the
notificationProvider
to display notifications based on the response from the backend. The notificationProvider
is an object with open
and close
methods that refine uses to show and hide notifications. These methods can be called from anywhere in the application with the useNotification
hook.
Here's an example of how you can define a notificationProvider
:
The open
method is invoked when refine wants to display a notification. It takes an object with the following shape as an argument:
The message
property is the message to display on the notification, and the type
property describes the type of the notification. A refine notification can be of type "success"
, "error"
, or "progress"
.
You can then pass the notificationProvider
to the <Refine>
component like so:
For more information, you can refer to the refine documentation (https://refine.dev/docs/api-reference/core/providers/notification-provider).
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@1073419683014922323> kapa.ai is still learning and improving, please let us how it did by reacting below
mute-gold•15mo ago
@Omer @alicanerdurmaz can you help please ?