Simple utility to simplify react notifications.
Applies animation properties to your notification components
npm install @ambiere/react-notificationimport ReactNotification from "react-notification"
useEffect(()=>{
//.....
const notification = new ReactNotification({
message: "Notification message",
timeout: 2500,
root: "root",
animation: "animation",
formatter(message) {
return message.concat(" :)")
}
})
notification.notify(()=>navigate("/home"))
//....
})
return (
//....
<div className="notification">
//....
<p className="root"></p>
</div>
)NB: The notification node wrapper should have a className of
notification, react-notification internally query the node wrapper usingnotificationclass selector.
type: function
Custom function to format notification message
- Param:
message- Raw unformatted text, internally supplied as the first argument of the formatter function. - Returns:
message- Formatted text.
type: number
default: 2500
Time in milliseconds a notification will be displyed before disappearing.
type: string
Raw unformatted notification message.
type: string
default: notification
Node class selector, where notification content will be populated.
type: string
CSS class selector containing animation properties to be applied on notification node wrapper.
type: function
Function that applies animation properties to the notification node wrapper. Accept a callback function that will be executed after animation is completed
- Param:
cb- Optional callback function
type: function
Function that populate notification message in notification node specified by node class selector, root.
- Returns:
depopulate()- Function that depopulate notification message from notification node specified by node class selector,root.