How to Add Notifications to your React Navigation bar
Tags: webdev, react, beginners, tutorial
Published: 2022-11-24 11:31:59

## Introduction

This article shows you how to add notifications your react navbar. It shows you how to show / hide the notifications feature, how to set recent notifications, how to change the bell icon, how to listen to callbacks and how to do further styling.

## Prerequisites

This article assumes that you have read the previous navbar tutorials. In case you haven't you will find a consolidated list in the reference links section. This article assumes that you have installed the Superflows library, have the default navigation bar up and running, have added your brand information, have also customised your menu, have added the search input, have configured the sign in button, have understood how to insert user profile information into the navbar and have seen how to add a back button to the navbar. This tutorial takes it forward from there.

## Step 1 - Display the Notification Section

By default notifications are visible. To show them, set the showNotification prop to true. You will see that the notification bell is now visible. Go ahead, click on it! A notification list will drop down. This is the default list, you can of course change it. 

```
function Apps(props) {
  
    return (
        <div>
            <SfNav />
            <br />
            <SfNav showNotification={true}/>
        </div>
    );
}
```

It renders as follows:

![onoff](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s754puypyi4rjeil8ave.png)

![onoffmobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0eh14qpnroruz3skl5et.png)

## Step 2 - Customize the Notification List

The notification list can be customized by passing a json array to the notificationList prop. Look at the example below.

```
function Apps(props) {
  
    return (
        <div>
            <SfNav showNotification={true} notificationList={[
                {id: 1, title: "New Follower!", description: 'Ram Joshi has started following you', timestampReceived: "2 days ago", read: false},
                {id: 2, title: "Richa reacted to your comment", description: 'Thanks I feel the same', timestampReceived: "5 days ago", read: true}]} />
        </div>
    );
}
```

It renders as follows:

![list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ureaof1ivy2eva9u3960.png)

![list_mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhro9wtn24w7uk9vnlfz.png)
## Step 3 - Change the Bell Icon

The default bell icon is from the unicode character set. You can use any icon and icon library of your choice. To change the bell icon, pass your icon object to the notificationIcon prop.

```
import {Bell} from 'react-bootstrap-icons';
```
```
function Apps(props) {
  
    return (
        <div>
            <SfNav showNotification={true} notificationIcon={<Bell style={{marginTop: '5px'}}/>} />
        </div>
    );
}
```

It renders as follows:

![bell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6gl7n3ra1vosbvs9oj5c.png)

![bell_mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/peswxbrjtybjrxuicx38.png)

**New Notification Indication**

If the notification list contains an unread notification, a red badge notification indicator will be shown on the notification icon. If all the notifications are read, it is not shown.

## Step 4 - Listen to the Notification Click Callback

Subscribe to the onNotificationClicked prop to listen to the notification click events.

```
function Apps(props) {
  
    return (
        <div>
            <SfNav showNotification={true} onNotificationClicked={(value) => {alert('Clicked on notification: ' + value.title)}} />
        </div>
    );
}
```

## Step 5 - Listen to the View All Click Callback 

Subscribe to the onViewAllClicked prop to listen to the view all button press event.

```
function Apps(props) {
  
    return (
        <div>
            <SfNav showNotification={true} onViewAllNotificationsClicked={() => {alert('On View All Clicked')}} />
        </div>
    );
}
```

## Step 6 - Styling

If you are interested in obtaining complete control over the look and feel, you already have it. You can completely override the base css properties of the notification elements according to your requirements. Showing you an example below.

```
function Apps(props) {
  
    return (
        <div>
            <SfNav 
                showNotification={true} 
                onViewAllNotificationsClicked={() => {alert('On View All Clicked')}} 
                notificationList={[
                    {id: 1, title: "New Follower!", description: 'Ram Joshi has started following you', timestampReceived: "2 days ago", read: false},
                    {id: 2, title: "Richa reacted to your comment", description: 'Thanks I feel the same', timestampReceived: "5 days ago", read: true}]}
                stylesNotificationIcon={{backgroundColor: '#ddd', color: 'black', height: '30px', width: '30px', justifyContent: 'center', borderRadius: '15px'}}
                stylesNotificationUnRead={{backgroundColor: 'black'}}
                stylesNotificationViewAll={{color: 'black'}}
                notificationIcon={<Bell style={{marginTop: '5px'}} />}  />
        </div>
    );
}
```

It renders as follows:

![advanced](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlf3461z82gl60jqpbka.png)

![advanced_mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2z9u7sihbik42m2ewah5.png)

## Reference Links

### Documentation

[This link](https://superflows.dev/docs/building-blocks/nav)

### Example Project For This Tutorial

[This link](https://stackblitz.com/edit/react-ts-sxet3i?file=App.tsx)

### Previous Tutorials of Navbar

### Previous Tutorials of Navbar

- [T1: Getting Started With Navbar](https://blog.superflows.dev/how-to-get-started-with-a-navigation-bar-in-your-react-project-in-2-mins)
- [T2: Insert Brand Info](https://blog.superflows.dev/how-to-customize-the-react-navbar-with-your-brand-info)
- [T3: Customise Menu](https://blog.superflows.dev/how-to-customize-the-menu-of-your-react-navbar)
- [T4: Add Search Functionality](https://blog.superflows.dev/how-to-implement-search-functionality-in-your-react-navbar)
- [T5: Add Sign In Button](https://dev.to/superflowsdev/how-to-add-a-sign-in-button-to-your-react-navbar-1c5b)
- [T6: Add User Profile Info](https://dev.to/superflowsdev/how-to-insert-user-profile-info-into-your-react-navbar-4hn2)
- [T7: Add Back Button](https://dev.to/superflowsdev/how-to-add-a-back-button-to-your-react-navbar-5c36)

### YouTube Channel

[This link](https://www.youtube.com/channel/UCYNJLCE48yir4DsquciBuDw)

### Discord Community

[This link](https://discord.gg/ksEXS4P9h6)

### Example Projects Collection

[This link](https://stackblitz.com/@superflows-dev/collections/navigation-bar)

## Video Tutorial

{% youtube lsqwMUipZTg %}

## Conclusion

You have already seen how to get started with the navigation bar, how to insert brand information into it, how to customise the menu and now, how to configure the search input, how to use the sign in button, how to insert profile information into it, how to add a back button and now how to add notifications to it.

This article shows you how to show the notifications section, customize the icon & notification list, listen to callbacks and how to style it.