documentation/versioned_docs/version-4.xx.xx/notification/hooks/use-notification/index.md
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import BasicUsageLivePreview from "./_basic-usage-live-preview.md";
useNotification can be used to open or close notification at any time. It returns the open and close method from notificationProvider under the hood.
Here is a basic example of how to use useNotification hook.
const { open, close } = useNotification();
// open notification
open?.({
type: "success",
message: "Success",
description: "This is a success message",
});
// close notification
close?.("notification-key");
You can call this method to open a new notification box.
const { open } = useNotification();
open?.({
type: "success",
message: "Success",
description: "This is a success message",
});
For more information, refer to the
Open Notification Paramsinterface→
You can close a notification with a key.
const { close } = useNotification();
close?.("notification-key");
You must pass a key to the open method. This key is used to close the notification.
It should be type=progress to show undoable notifications. A function can then be triggered.
const { open } = useNotification();
open?.({
type: "progress",
message: "Progress",
undoableTimeout: 5,
cancelMutation: () => {
// when undo button is clicked, run this callback
},
});
| Property | Description | Type |
|---|---|---|
| open | Open Notification Params | Open Notification Params |
| close | Close Notification Params | (key: string) => void; |