Tutorials

Show Alert Notification Messages Using React.js Notyf Library

npx create-react-app alertdemo
cd alertdemo
npm i notyf

Notyf is a minimalistic JavaScript library for toast notifications. It is responsive, A11Y compatible, dependency-free, and has a very lightweight footprint (~3KB). Notyf can be easily integrated with React, Angular, Aurelia, Vue, and Svelte.

Features

  • Responsive
  • A11Y compatible
  • Strongly typed codebase (TypeScript Typings readily available)
  • 4 types of bundles exposed: ES6, CommonJS, UMD, and IIFE (for vanilla, framework-free usage).
  • End-to-end testing with Cypress
  • Easily plugable to modern frameworks. Recipes available to integrate with React, Angular, Aurelia, Vue, and Svelte.
  • Optional ripple-like fancy revealing effect
  • Simple but highly extensible API. Create your own toast types and customize them.
  • Support to render custom HTML content within the toasts
  • Tiny footprint (<3K gzipped)
  • Works on IE11

Usage in Browser

<html>
  <head>
    ...
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css">
  </head>
  <body>
    ...
    <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
  </body>
</html>

Basic Alert Messages in JavaScript

// Create an instance of Notyf
var notyf = new Notyf();

// Display an error notification
notyf.error('You must fill out the form before moving forward');

// Display a success notification
notyf.success('Your changes have been successfully saved!');

Examples

Global Configuration

The following example configures Notyf with the following settings:

  • 1s duration
  • Render notifications in the top-right corner
  • New custom notification called ‘warning’ with a ligature material icon
  • Error notification with custom duration, color and dismiss button
const notyf = new Notyf({
  duration: 1000,
  position: {
    x: 'right',
    y: 'top',
  },
  types: [
    {
      type: 'warning',
      background: 'orange',
      icon: {
        className: 'material-icons',
        tagName: 'i',
        text: 'warning'
      }
    },
    {
      type: 'error',
      background: 'indianred',
      duration: 2000,
      dismissible: true
    }
  ]
});

Custom toast type

const notyf = new Notyf({
  types: [
    {
      type: 'info',
      background: 'blue',
      icon: false
    }
  ]
});

notyf.open({
  type: 'info',
  message: 'Send us <b>an email</b> to get support'
});

Full Source Code to Show Alert Notification Messages Using React.js Notyf Library

App.js

import React from 'react'

import { Notyf } from 'notyf';
import 'notyf/notyf.min.css'; // for React, Vue and Svelte

function App() {


  const notyf = new Notyf();

  const successAlert = () => {

    notyf.success("This is a basic Alert")
   
  }

  const errorAlert = () => {
    let error = new Notyf({
      duration:1000,
      position:{
        x:'right',
        y:'top'
      },
      dismissible:true
    })
    error.error("This is an error Alert")
  }

  const customAlert = () => {
    const notyf = new Notyf({
      types: [
        {
          type: 'custom',
          background: 'blue',
          icon: false
        }
      ]
    });
    
    notyf.open({
      type: 'custom',
      message: 'Send us <b>an email</b> to get support'
    });
  }
  return (
    <div>
      <button onClick={successAlert}>Success Alert</button>
      <button onClick={errorAlert}>Error Alert</button>
      <button onClick={customAlert}>Custom Toast Alert</button>
    </div>
  )
}

export default App

Screenshot

Show Alert Notification Messages Using React.js Notyf Library
Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

MiniMax-M1 vs GPT-4o vs Claude 3 Opus vs LLaMA 3 Benchmarks

MiniMax-M1 is a new open-weight large language model (456 B parameters, ~46 B active) built with hybrid…

June 22, 2025

How to Use Husky with npm to Manage Git Hooks

Managing Git hooks manually can quickly become tedious and error-prone—especially in fast-moving JavaScript or Node.js…

June 22, 2025

How to Use Lefthook with npm to Manage Git Hooks

Git hooks help teams enforce code quality by automating checks at key stages like commits…

June 22, 2025

Lefthook vs Husky: Which Git Hooks Tool is Better? [2025]

Choosing the right Git hooks manager directly impacts code quality, developer experience, and CI/CD performance.…

June 22, 2025

Llama 3.1 vs GPT-4 Benchmarks

We evaluated the performance of Llama 3.1 vs GPT-4 models on over 150 benchmark datasets…

July 24, 2024

Transforming Manufacturing with Industrial IoT Solutions and Machine Learning

The manufacturing industry is undergoing a significant transformation with the advent of Industrial IoT Solutions.…

July 6, 2024