npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-notifications-cascade

v2.0.0

Published

A flexible notification system with action button support, configurable duration, and backwards compatibility built with React and Material UI

Readme

react-notifications-cascade

A sleek, animated notifications system built with React and Material UI that displays notifications in the bottom-right corner of the screen, animates them upward in a cascade style, and automatically removes them after 5 seconds.

What's New in Version 2

  1. Action button support - Optional action parameter with customizable behavior
  2. Configurable duration - Set custom auto-dismiss time or make persistent
  3. Enhanced helpers - showSuccessWithAction() and similar methods
  4. 100% backwards compatible - All existing code continues to work

Features

  • 🚀 Animated Transitions - Smooth slide-up animation for incoming notifications
  • ⏱️ Auto-Dismissal - Notifications automatically disappear after 5 seconds
  • 🎨 Material UI Styling - Attractive, modern design using Material UI components
  • 🔄 Four Notification Types - Success, error, warning, and info variants
  • 🌐 Global Access - Context API for easy access from any component
  • ✖️ Manual Dismissal - Close notifications early with the built-in close button
  • 🧩 Highly Customizable - Easy to extend and modify

Installation

# Using npm
npm install react-notifications-cascade

# Using yarn
yarn add react-notifications-cascade

# Using pnpm
pnpm add react-notifications-cascade

Peer Dependencies

This package requires the following peer dependencies:

# Using npm
npm install react react-dom @mui/material @mui/icons-material @emotion/react @emotion/styled

# Using yarn
yarn add react react-dom @mui/material @mui/icons-material @emotion/react @emotion/styled

# Using pnpm
pnpm add react react-dom @mui/material @mui/icons-material @emotion/react @emotion/styled

Usage

1. Wrap Your App with the Provider

In your root component (typically App.js), wrap your application with the NotificationsProvider:

import { NotificationsProvider } from 'react-notifications-cascade';

function App() {
  return (
    <NotificationsProvider>
      {/* Your app components */}
    </NotificationsProvider>
  );
}

export default App;

2. Use Notifications in Any Component

Use the useNotifications hook to access notification functions:

import { useNotifications } from 'react-notifications-cascade';

function MyComponent() {
  const { showSuccess, showError, showWarning, showInfo } = useNotifications();

  const handleSaveSuccess = () => {
    showSuccess('Data saved successfully!');
  };

  const handleApiError = () => {
    showError('Failed to connect to the server. Please try again.');
  };

  return (
    <div>
      <button onClick={handleSaveSuccess}>Save Data</button>
      <button onClick={handleApiError}>Simulate Error</button>
      <button onClick={() => showWarning('Battery is low!')}>Show Warning</button>
      <button onClick={() => showInfo('New updates available')}>Show Info</button>
    </div>
  );
}

3. Demo Component (Optional)

The package includes a ready-to-use demo component for testing or showcasing purposes:

import { NotificationsProvider } from 'react-notifications-cascade';
import { NotificationsDemo } from 'react-notifications-cascade/demo';

function App() {
  return (
    <NotificationsProvider>
      <NotificationsDemo />
      {/* Your other app components */}
    </NotificationsProvider>
  );
}

API Reference

NotificationsProvider

The main provider component that makes notifications available throughout your app.

Props

  • children - React nodes to be wrapped by the provider

useNotifications Hook

A custom hook for accessing notification functions.

Returns

An object containing:

  • notifications - Array of current notification objects
  • addNotification(message, type) - Add a custom notification
  • removeNotification(id) - Remove a notification by ID
  • showSuccess(message) - Show a success notification
  • showError(message) - Show an error notification
  • showWarning(message) - Show a warning notification
  • showInfo(message) - Show an info notification

Notification Object Structure

Each notification has the following properties:

{
  id: string;            // Unique identifier
  message: string;       // Notification message
  type: string;          // 'success' | 'error' | 'warning' | 'info'
  timestamp: Date;       // When the notification was created
}

Customization

Changing Duration

To change the auto-dismissal duration, modify the timeout value in the addNotification function:

// Change from 5000ms (5 seconds) to your desired duration
setTimeout(() => {
  removeNotification(newNotification.id);
}, 5000); // ← Modify this value

Styling

The notifications use Material UI's Alert and Snackbar components. You can customize their appearance by modifying the sx prop in the NotificationsContainer component.

Example

import { useNotifications } from 'react-notifications-cascade';

function UserForm() {
  const { showSuccess, showError } = useNotifications();
  
  const handleSubmit = async (e) => {
    e.preventDefault();
    try {
      // API call to save user data
      await saveUserData(userData);
      showSuccess('User profile updated successfully!');
    } catch (error) {
      showError(`Failed to update profile: ${error.message}`);
    }
  };
  
  return (
    <form onSubmit={handleSubmit}>
      {/* form fields */}
      <button type="submit">Update Profile</button>
    </form>
  );
}

TypeScript Support

This package includes TypeScript declarations for improved developer experience.

// Example TypeScript usage
import { useNotifications } from 'react-notifications-cascade';
import { FC, FormEvent } from 'react';

interface UserData {
  name: string;
  email: string;
}

const UserForm: FC = () => {
  const { showSuccess, showError } = useNotifications();
  
  const handleSubmit = async (e: FormEvent) => {
    e.preventDefault();
    try {
      // API call
      showSuccess('Success!');
    } catch (err) {
      showError(`Error: ${err instanceof Error ? err.message : String(err)}`);
    }
  };
  
  return <form onSubmit={handleSubmit}>...</form>;
};

Browser Support

react-notifications-cascade is compatible with all modern browsers and React 16.8 or higher (requires Hooks support).

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request