# React-Notifications ⚠️

Here I’ll show how we can handle notifications in our React project. First, we’ll be using **react-notifications**🔔, which, as its name suggests, is a notification component for React.

## Installation:

Go to the client *project directory* and install the following npm package:

 `npm install --save react-notifications`
    or
 `yarn add react-notifications`

## Setting up the Notification container:

Now update the *App.js* file. Import *NotificationContainer* from react-notifications and the _notifications.css_ file. 

```javascript 
...
// React Notification
import 'react-notifications/lib/notifications.css';
import { NotificationContainer } from 'react-notifications';
...
...
return (
 <Router>
  <div>
   ...
   ...
   <NotificationContainer />
  </div>
 </Router>
);
```

So far, we have completed our setup for *NotificationContainer*.

> NOTE: Use only one NotificationContainer component in the app.

Now it’s time to pass notifications from different components to display their message.

## Setting Notifications from components:

```javascript 
// React Notification
import { NotificationManager } from 'react-notifications';

// Add this line where you want to show the notification
NotificationManager.info('Hey I am Adyasha', 'Info!', 2000);

```
Horray, you did it. Now you can run your project.

## Available NotificationManager APIs:

You can apply this same method to different components in your project. Notifications will be displayed in different colors depending on the notification type.
For this package, there are four different APIs available to us of the following types:

- info
- success
- warning
- error

![Image](https://cdn.hashnode.com/res/hashnode/image/upload/v1688718740024/198627a0-67c5-4ff3-a7ba-14de3ab7297b.png)

Here’s an example for the _success_ type — simply replace _success_ with the proper notification type for the given situation :

` NotificationManager.success(message, title, timeOut, callback, priority); `

> You can also pass five different parameters along with the message: _message_, _title_, _timeOut_, _callback_, and _priority_.

The parameters that follow the notification type are described below:

- _message_: The message we want to pass. It has to be a string.

- _title_: The title of the notification. Again, its type is a string.

- _timeOut_: The popup timeout in milliseconds. This has to be an integer.

- _callback_: We can pass a function (type; function) through the notification. It executes after the popup is called.

- _priority_: This is a boolean parameter. We can push any notification to the top at any point by setting the priority to true.

That's all. Thanks for your patience ❤️! Have a nice day ;)

Find me on Twitter [@Adyasha8105](https://twitter.com/Adyasha8105)👀.
