quickest-silver•3mo ago
How to create notification provider from scratch?
How to create notification provider from scratch and show the notification once an action is success or failed ? for example after updating a data, or creating a record?
2 Replies
Hi @regn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To create a notification provider from scratch in Refine, you need to implement an object with
- Implement a
open and close methods that conform to the NotificationProvider interface. This provider can then be passed to the <Refine> component via the notificationProvider prop. Here’s how you can do it, using a popular toast library like react-toastify as an example:
---
1. Install a Toast Library
For example, with react-toastify:
How to create a notification provider with react-toastify
---
2. Create the Notification Provider
Create a file (e.g., src/providers/notificationProvider.tsx) and implement the provider:
Notification Provider - Creating from scratch
---
3. Add Toast Container to Your App
In your main app file, add the ToastContainer component and pass your provider to <Refine>:
Notification Provider - Usage
---
4. Show Notifications on Success or Failure
Refine’s data hooks (like useUpdate, useCreate, etc.) automatically trigger notifications using the provider when actions succeed or fail. You can also customize these notifications per action:
Customizing Notifications
Alternatively, you can trigger notifications manually anywhere in your app using the useNotification hook:
Notification Provider - useNotification hook
---
Summary:- Implement a
notificationProvider with open and close methods.
- Pass it to <Refine>.
- Use Refine’s hooks or useNotification to show notifications on action success or failure.
This approach works with any toast library, not just react-toastify. You can adapt the logic for other libraries like react-hot-toast as well.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@336843331416096768> Kapa.ai is still learning and improving, please let me know how I did by reacting below.