Guide to building a Real-time Notification System in React

featured article thumbnail

You’ve been tasked with implementing a notification system into your product. There are two options: you (and your team) can build a system yourselves—a custom notification system—or you can implement a free or paid third-party tool. Before deciding, you need to know the goals of the system (is it driving objectives and key results?), as well as how it might grow based on performance. If notifications aren’t your core business, the decision to custom-build a notification solution can have long-lasting implications.

Know what goes into building a React notification system before you commit to any solution, and weigh the buy-versus-build options. For the purposes of this article, we’ll be focusing on the frontend implementation.

Here’s what we’ll go over in this guide:

  • The expenses of a custom React notification system

  • The benefits of a third-party solution

  • Integrating MagicBell into your React frontend

Introduction to React Notifications

React notifications are a vital component of any modern web application, serving as the primary channel for delivering timely updates, alerts, and important information directly to users. A thoughtfully designed notification system in React not only keeps users informed but also plays a significant role in enhancing user engagement. Whether you’re displaying simple toast notifications for success messages or building a fully-featured notification center, the right approach can make your application more interactive and responsive to user needs.

By leveraging react notifications, developers can create a seamless experience that encourages users to stay active within the app, respond to critical events, and never miss out on essential updates. From alerting users about new messages to notifying them of system changes, a robust notification system is key to keeping users engaged and satisfied. Notifications in React can be implemented in various forms, including lightweight toast notifications for quick feedback or more complex, totally customizable components for in-depth user interactions. Ultimately, integrating an effective notification system is a proven way to enhance user engagement and drive the success of your application.

Types of Notifications in React

When designing notification systems in React, it’s important to understand the different types of notifications you can implement, as each serves unique purposes and user experiences. Broadly, notifications in React fall into two main categories: stateless and stateful notifications.

Stateless notifications are simple, one-off messages that don’t retain any information about previous notifications. These are commonly used for toast notifications, quick alerts, or success messages that briefly inform users of an action’s outcome. Stateless notifications are ideal for scenarios where you want to provide immediate feedback without requiring further user interaction or tracking.

On the other hand, stateful notifications maintain a record of notification history and user interactions. These are essential for more advanced notification systems, such as in app notifications, notification feeds, or a dedicated notification center UI. Stateful notifications allow users to view, dismiss, or interact with past notifications, making them suitable for applications that require persistent and interactive user engagement.

Beyond these categories, notification types can also be defined by their delivery mechanisms. Push notifications, for example, enable you to send notifications to users even when they’re not actively using your web app, while in app notifications are delivered and displayed while users are engaged with your application. Web push notifications leverage browser capabilities to reach users across different platforms, expanding your reach and keeping users informed in real time.

Understanding these notification types and their respective use cases is crucial for building a custom React notification system that meets your application’s needs. By choosing the right combination of notification types—whether it’s toast notifications for quick feedback or a full-featured notification center for ongoing updates—you can ensure your notification system is both effective and user-friendly.

The expenses of a custom React notification system

Before you commit to a marathon notification project, you need to know exactly what you’re getting into, how notifications can snowball, and the hidden costs. There are tools available to help you build a custom React notification system, but the reality is many might not offer exactly what you need or cause you to find secondary and tertiary solutions to implement.

For example, browser support for the various APIs differs greatly, so, in the case of reaching all your users (Safari 👀), you might need multiple custom solutions. Additionally, backend components are essential for enabling real-time updates and seamless user engagement in a notification system.

Push API vs. Notifications API

Even if we break down a notification system into just one type — desktop push notifications — there are still some fundamental choices to be made. You can push notifications to your users if they’re on your web app, or you can push them to your users even if your web app isn’t loaded. But these two types of notifications don’t have the same support and require different implementations.

Notifications API: The Notifications API lets you send out notifications to those who have your web app loaded, regardless of whether it’s focused. Not only should you get permission from users before you start sending them messages, but you also need to be careful about how you go about it.

Browsers have started blocking web apps from requesting permission in a spam-like manner, as well as those who continue to request even after a user has denied permission. This API is pretty straightforward: user has web app open, request permission, send notifications.

Push API: The Push API is probably very exciting to marketers and strategists alike. With it, after receiving permission, you can send notifications to users even if your web app isn’t loaded. This allows you to send marketing, sales, and promotional content whenever you want.

Unlike mobile push, which is universally accepted as a way of life at this point, web push, in the same manner, is not. The support for this type of web push is low, meaning it’s only effective if your customers happen to be using the various browsers and devices that support it.

Safari is only partially supported with the Notifications API and not supported at all by the Push API. A custom solution that needs to target Safari users will require a secondary custom solution that integrates Apple’s own method. For sending push notifications to iOS devices, the Apple Push Notification Service (APNs) is required. Integrating with APNs ensures compatibility with Apple hardware and allows notifications to reach users on iOS devices.

A growing Notification system

There’s more to a fully-fledged React notification system than just desktop push messages. While a request for such a system might start small with one type of notification, the success of that implementation can (and will likely) expand into requests for other types of notification implementations. A full notification system would likely include most or all of the following notification types:

  • Web push

  • Mobile push

  • SMS

Managing user notifications across these channels requires a robust notification feed, which allows users to access their notification history and ensures persistent engagement.

As we’ve mentioned, a custom solution for web push will need multiple solutions to reach all browser and device users. Mobile push will require a separate solution as well. Both systems will need to be permission-based, with service workers and a server handling the sending of notifications. You’ll also have to make sure that when a user revokes permission, it can be handled by the system.

SMS and email notifications require you to collect personally identifiable information (PII), mainly a phone number or email address. This means you have to make sure your system is compliant with privacy acts like GDPR and CCPA.

Before implementation, if stakeholders have the data and insights about how certain notification types will benefit the product and the users, then you’re in a good situation. Another (and more likely) scenario could be that one type of notification will be requested, and based on the success or failure of that implementation, it will go through iterations or expansion.

Hidden costs

Sometimes custom solutions are necessary, but with that comes all the hidden costs that need to be considered. With developers only spending around 32% of their time actually writing code, undertaking a custom-built React notification system (that will likely grow) is a large step.

With your time already split between various tasks, there are some specific hidden costs with notification systems to take into account.

We’ve already mentioned that notifications are supported differently on some devices and browsers, so separate custom implementations will need to be worked out to get the coverage you need.

After a React notification system is built, you’ll likely also be required to set up A/B tests for content, timing, and other variables. Testing different notification content is crucial for optimizing user engagement and ensuring the right messages are delivered at the right time. These tests will ensure you’re sending the right messaging at the right time to the right users. All of that A/B testing data needs to get stored properly (ideally, a single source of truth) to make sure it’s easily readable by data teams. That’s a lot to take on.

Takeaway

While there can be benefits to building a custom solution, like full control over the design and implementation, a homespun solution is probably more trouble than it's worth. Unless your core business is notifications, building and maintaining a notification system in-house is a large commitment for a development team.

The benefits of a third-party solution

Using a third-party tool for your notifications gets bug fixes, browser compatibility, and a large portion of maintenance tasks off your plate. These tools often come with advanced features such as customization options, programmatic controls, and support for animations. As the notification system needs to grow with the product, expansion is easier and less stressful.

Beyond the basics

Beyond permission requests and a message, third-party tools offer out-of-the-box features you can implement as stakeholders make requests and the system expands. You don’t need to build your own React notification system to have a successful notification implementation. Notification tools quite obviously make notifications their business, and in addition to multiple features, they take a lot of the testing and maintenance of the core system off your plate.

Types of notifications: As we’ve already mentioned, a notification system can expand to include more than web or mobile push. Email and SMS notifications can be added to the equation, requiring completely different implementations and compliance checks. Third-party notification tools will have tiers or add-ons for expansion into different notification types as your system grows.

Segmentation: Segmenting users allows for targeted and customized messages. Groupings based on language, location, and habits allow you to notify those who will benefit the most. By targeting specific users with specific notifications, you can add value to the user experience. Building custom segmenting tools on top of your custom notification solutions is a headache.

UIs for non-devs: UIs and dashboards are an incredibly useful tool. UIs give stakeholders and non-devs ways to make updates and changes, and dashboards can give insights into data. With these features, you won’t have to update notification copy, parse data, or relay as much info to the data team. Not having to build these UIs and dashboards internally will be a huge time-saver. Loading indicators are integrated features in many notification libraries, providing visual cues during ongoing actions and enhancing the user experience.

Customization Options

Third-party tools understand that branding is important, so customization options will exist to match your brand style. Whether you’re starting with toast notifications or implementing a full notification solution, you’ll have options to try out, ensuring you can match your brand and strategy. Libraries like react notifications component offer a totally customizable component for implementing notifications in React applications.

Brand matching: Fonts, colors, and icons can be integrated into third-party tools, ensuring your brand’s style isn’t lost in the notification process.

Custom animations: Toast and certain browser notifications leave a lot of room for customization and animations, including their badges. Third-party libraries will often have options to override the default CSS they’ve provided, opening up the possibilities for complete customization.

React-toastify* playground with fun style and animations*

Takeaway

On a surface level, notifications might not seem like a large ask. But they can become feature-complex depending on the growth strategy. Once a notification system is implemented, it needs to be monitored and maintained, possibly creating a disturbance in your development cycles. Using a third-party tool mitigates the responsibility of maintaining a full notification system.

Integrate MagicBell into your React frontend

We’re going to skip over the back-end integration and focus on how to implement a MagicBell notification inbox into your React frontend. The notification inbox can be implemented in a few ways, in a few short steps, with customizable options.

The default Inbox spans the entire width of the page when opened (note: you can control the height through properties).

// App.jsx

import * as React from 'react';
import Provider from '@magicbell/react/context-provider';
import Inbox from '@magicbell/react/inbox';

export default function NotificationDemo() {
  return (
    <Provider token={USER_JWT}>
      <Inbox />
    </Provider>
  );
}

The FloatingInbox is a tooltip with the ability to control the width and height through properties.

// App.jsx

import * as React from 'react';
import Provider from '@magicbell/react/context-provider';
import FloatingInbox from '@magicbell/react/floating-inbox';

export default function FloatingInboxDemo() {
  return (
    <Provider token={USER_JWT}>
      <FloatingInbox placement="bottom-start" height={500} width={400} offset={10} />
    </Provider>
  );
}

The Provider component acts as a React component that leverages the Context API to manage notification state across the application, making it easier to share notification data between components. This creates a MagicBellContext and keeps notifications updated in real time through a connection to magicbell.com.

// Layout.tsx

import * as React from "react";
import Provider from "@magicbell/react/context-provider";

function Layout(props: any) {
  return (
    <main>
      <Provider token={USER_JWT}>
        { children }
      </Provider>
    </main>
  );
}

export default Layout;

And then you can use the Inbox component on any page:

// NotificationPage.tsx

import * as React from "react";
import Layout from "../components/layout";
import FloatingInbox from "@magicbell/react/floating-inbox";

function NotificationPage(props: any) {
  return (
    <Layout>
      <FloatingInbox
        placement="bottom-start"
        height={500}
        width={400}
        offset={10}
      />
    </Layout>
  );
}

export default NotificationPage;

Handling notifications efficiently in the frontend ensures users receive timely updates and improves the overall user experience.

Custom themes

The MagicBell Inbox has multiple elements that can be styled using CSS classes. You can overridde the default CSS styles by specifying the classes in a CSS stylesheet.

You can style Inbox elements like:

  • Header: magicbell--inbox-header

  • Footer: magicbell--inbox-footer

  • Inbox Container: magicbell--inbox

  • Notification Item: magicbell--inbox-item

  • Buttons: magicbell--button

  • Floating Menu: magicbell--floating-menu

Customizing the notification UI in this way ensures a responsive user interface that adapts to different devices and user needs.

body .magicbell--inbox {
  /* Text colors */
  --magicbell-text-default: #f5f5f5;
  --magicbell-text-muted: #9ca3af;
  --magicbell-text-link: #3b82f6;
  --magicbell-text-link-hover: #60a5fa;

  /* Border & background */
  --magicbell-border-muted: #374151;
  --magicbell-bg-default: #111827;
  --magicbell-bg-hover: #1f2937;
  --magicbell-bg-active: #374151;

  /* Surfaces */
  --magicbell-surface-bg: #1f2937;
  --magicbell-surface-bg-hover: #2d3748;
  --magicbell-surface-bg-active: #374151;
  --magicbell-surface-text: #f9fafb;
  --magicbell-surface-text-hover: #f9fafb;
  --magicbell-surface-text-active: #f9fafb;

  /* Shadows */
  --magicbell-shadow-elevated: 0 0 6px rgba(0, 0, 0, 0.4), 0 5px 12px rgba(0, 0, 0, 0.6);
}

body .magicbell--inbox > :not(.magicbell--inbox-header) {
  scrollbar-gutter: stable;
  scrollbar-color: #4b5563 #1f2937; /* thumb, track */
  scrollbar-width: thin;
  background-color: #111827;
}

body .magicbell--inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: none;
  padding: 12px;
  background: #111827;
}

See a full demo of the FloatingInbox implementation on CodeSandbox.

Takeaway

It's easy to request an API key and try out the React SDK in your own app or in a sandbox online!

Easily implemented, ready to grow notifications with MagicBell

MagicBell provides a fast and easy way to implement a solution for your React notification system needs. Visit the docs to see how to integrate MagicBell into your back end and frontend. MagicBell can also be integrated alongside services like Firebase Cloud Messaging to deliver notifications reliably across platforms such as Android and iOS. Our notification inbox can be implemented with various SDKs and tools that have been created. MagicBell supports building a real time notification center for timely user engagement and alerts.

Your notification system with MagicBell can grow with the product, with options for in-app, web push, mobile push, email, and SMS. Sign up and get instant access to your API key here.

Related articles: