How to Insert User Profile Info into your React Navbar
Tags: tutorial, react, superflows, webdev
Published: 2022-11-09 10:15:29

## Introduction

This article shows you how to insert the profile information of any user into the react navigation bar, so as to make it sign-in aware. It shows you how to insert and configure the profile picture & menu, how to reuse the sign in button, how to handle callbacks and then it will discuss the 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 and have also configured the sign in button. This tutorial takes it forward from there.

## Step 1 - Insert the Profile Picture

To show the profile picture, set the showProfile prop to true and set the profile picture url string to the profilePicture prop. 

```
return (
        <div>
                <SfNav showProfile={true} profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' />
        </div>
);
```

It renders as follows:

![Profile picture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymlchw8foee66k5enp40.png)

![Profile picture mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pqlwc86zyv1612hlx6l.png)

## Step 2 - Populate the Profile Menu

Profile menu can be populated by passing the requisite json array object to the profileMenu prop. I am showing an example here. You can look at how the json array object has been composed.

```
return (
        <div>
                <SfNav 
                  showProfile={true}
  profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' 
                  profileMenu={[{caption: "Profile", link: "profile"}, [{caption: "Settings", link: "support"}, {caption: "Notifications", link: "notifications"}, {caption: "Privacy", link: "privacy"}], {caption: "Support", link: "support"}, {caption: 'Upgrade', link: "upgrade"}]} 
                />
        </div>
);
```

It renders as follows:

![Profile menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t39ndt3b7o8cmn9tbpc.png)

![Profile menu mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/efjj3ld5ccododmtondj.png)

## Step 3 - Extend the Functionality: Use Profile Preamble

The navigation bar provides you a container, just above the profile menu, where you can insert your own custom developed component. It is called the profile preamble. How to use it, is totally up to your imagination. In the example shown below, it provides some profile context to the user.

```
return (
        <div>
                <SfNav 
                  showProfile={true}
  profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' 
                  profileMenu={[{caption: "Profile", link: "profile"}, [{caption: "Settings", link: "support"}, {caption: "Notifications", link: "notifications"}, {caption: "Privacy", link: "privacy"}], {caption: "Support", link: "support"}, {caption: 'Upgrade', link: "upgrade"}]} 
                  profilePreamble={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Hi Hrushi!</small><br /><small><small><i>Welcome to Superflows!</i></small></small></div>}
                />
        </div>
);
```

It renders as follows:

![Profile preamble](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syfu51nkrsokwogjfr66.png)

![Profile preamble mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itqqvvtaxdx66zr94aom.png)

## Step 4 - Extend the Functionality: Use Profile Component

The navigation bar provides you a second container, just below the profile menu, where you can insert another custom developed component. It is called the profile component. How to use it, is totally up to your imagination. In the example shown below, it show a sign out button.

```
return (
        <div>
                <SfNav 
                  showProfile={true}
  profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' 
                  profileMenu={[{caption: "Profile", link: "profile"}, [{caption: "Settings", link: "support"}, {caption: "Notifications", link: "notifications"}, {caption: "Privacy", link: "privacy"}], {caption: "Support", link: "support"}, {caption: 'Upgrade', link: "upgrade"}]} 
                  profilePreamble={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Hi Hrushi!</small><br /><small><small><i>Welcome to Superflows!</i></small></small></div>}
                  profileComponent={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Sign Out</small></div>}
                />
        </div>
);
```

It renders as follows:

![Profile component](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0blvaqknsyhmpm87c9uq.png)

![Profile component mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jptq124m90lzu25z5ove.png)
## Step 5 - Hide or Re-use the Sign In Button

User profile information is displayed usually only for the signed in user. In such a scenario, the sign in button is not necessary. You can either hide it or re-use it. The following example, re-uses it as a subscription button.

```
return (
        <div>
                <SfNav 
                  showProfile={true}
  profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' 
                  profileMenu={[{caption: "Profile", link: "profile"}, [{caption: "Settings", link: "support"}, {caption: "Notifications", link: "notifications"}, {caption: "Privacy", link: "privacy"}], {caption: "Support", link: "support"}, {caption: 'Upgrade', link: "upgrade"}]} 
                  profilePreamble={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Hi Hrushi!</small><br /><small><small><i>Welcome to Superflows!</i></small></small></div>}
                  signInCaption="Subscribe"
                />
        </div>
);
```

It renders as follows:

![Profile subscribe](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pcryygskm29v2pvppz4.png)

## Step 6 - Handle callbacks

To listen to the click event on the profile menu, subscribe to the onMenuClicked prop as shown. To listen to the click event on the subscribe (re-used sign in) button, subscribe to the onSignInPressed prop as shown below:

```
return (
        <div>
                <SfNav 
                  showProfile={true}
  profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' 
                  profileMenu={[{caption: "Profile", link: "profile"}, [{caption: "Settings", link: "support"}, {caption: "Notifications", link: "notifications"}, {caption: "Privacy", link: "privacy"}], {caption: "Support", link: "support"}, {caption: 'Upgrade', link: "upgrade"}]} 
                  profilePreamble={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Hi Hrushi!</small><br /><small><small><i>Welcome to Superflows!</i></small></small></div>}
                  profileComponent={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Sign Out</small></div>}
                  signInCaption="Subscribe"
                  onMenuClicked={(value)=>{alert(value)}}
                  onSignInPressed={()=>{alert('Subscribe pressed!')}}
                />
        </div>
);
```

## Step 7 - Styling

You can then customise the look and feel, by using inline css or by class names. The Superflows navigation bar exposes props that facilitate customisation. An example is shown below:

```
return (
        <div>
                <SfNav 
                  showProfile={true}
  profilePicture='https://i.pinimg.com/736x/7f/79/6d/7f796d57218d9cd81a92d9e6e8e51ce4--free-avatars-online-profile.jpg' 
                  profileMenu={[{caption: "Profile", link: "profile"}, [{caption: "Settings", link: "support"}, {caption: "Notifications", link: "notifications"}, {caption: "Privacy", link: "privacy"}], {caption: "Support", link: "support"}, {caption: 'Upgrade', link: "upgrade"}]} 
                  profilePreamble={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Hi Hrushi!</small><br /><small><small><i>Welcome to Superflows!</i></small></small></div>}
                  profileComponent={<div style={{width: '100%', paddingTop: '10px', paddingBottom: '10px', paddingLeft: '10px', paddingRight: '10px'}}><small>Sign Out</small></div>}
                  signInCaption="Subscribe"
                  onMenuClicked={(value)=>{alert(value)}}
                  onSignInPressed={()=>{alert('Subscribe pressed!')}}
                  stylesProfilePictureContainer={
                        {backgroundColor: 'black', padding: '2px', color: 'white', borderRadius: '5px'}
                      } 
                      stylesProfilePreamble={
                        {backgroundColor: 'white', color: 'black'}} stylesProfileComponent={{backgroundColor: 'white', color: 'black'}
                      } 
                      stylesMenu={
                        {backgroundColor: 'black', color: 'white', paddingTop: '3px', paddingBottom: '3px', paddingLeft: '10px', paddingRight: '10px', borderRadius: '5px'}
                      } 
                      stylesSubMenu={
                        {backgroundColor: 'black', color: 'white', paddingLeft: '5px', paddingRight: '5px', border: 'solid 1px gray'}
                      }
                      stylesMenuMobile={
                        {backgroundColor: 'black', color: 'white', paddingLeft: '5px', paddingRight: '5px', borderRadius: '5px', border: 'solid 1px gray'}
                      }
                      stylesMenuMobileSelected={
                        {backgroundColor: 'white', color: 'black', paddingLeft: '5px', paddingRight: '5px', borderRadius: '5px', border: 'solid 1px gray'}
                      }
                      stylesSubMenuMobile={
                        {backgroundColor: 'black', color: 'white', paddingLeft: '5px', paddingRight: '5px', borderRadius: '5px', border: 'solid 1px gray'}
                      }
                />
        </div>
);
```

It renders as follows:

![Profile styling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dnw3mdxdkvg8oesa97fn.png)

![Profile styling mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/353hozhdmuwt6syue34u.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-j8yq1f?file=App.tsx)

### 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)

### 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 8uXgtEb9Ucw %}

## Further Reading

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 and now, how to insert profile information into it.

## Conclusion

This article shows you how to insert profile information into your react navigation bar, how to customize the profile menu, how to extend the functionality by adding your own custom components and how to then style the profile section.