Convert Figma logo to code with AI

iamhosseindhv logonotistack

Highly customizable notification snackbars (toasts) that can be stacked on top of each other

4,026
297
4,026
64

Top Related Projects

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

React notification made easy 🚀 !

🍞 A toast notification system for react

Smoking Hot React Notifications 🔥

Delightful and highly customisable React Component to notify your users

1,557

:postbox: A simple and customizable React notifications system

Quick Overview

Notistack is a React library that simplifies the process of displaying snackbars (toast notifications) in web applications. It provides an easy-to-use API for managing multiple snackbars with different variants, positions, and behaviors, while also offering customization options.

Pros

  • Easy integration with Material-UI and other React projects
  • Supports stacking multiple notifications
  • Offers customizable appearance and behavior
  • Provides hooks for easy usage in functional components

Cons

  • Requires Material-UI as a peer dependency
  • Limited built-in animation options
  • May require additional setup for complex use cases
  • Documentation could be more comprehensive for advanced features

Code Examples

  1. Basic usage with hooks:
import { useSnackbar } from 'notistack';

function MyComponent() {
  const { enqueueSnackbar } = useSnackbar();

  const handleClick = () => {
    enqueueSnackbar('This is a success message!', { variant: 'success' });
  };

  return <button onClick={handleClick}>Show snackbar</button>;
}
  1. Custom snackbar with action:
import { useSnackbar } from 'notistack';
import Button from '@mui/material/Button';

function MyComponent() {
  const { enqueueSnackbar, closeSnackbar } = useSnackbar();

  const handleClick = () => {
    enqueueSnackbar('Custom snackbar', {
      variant: 'info',
      action: (key) => (
        <Button onClick={() => closeSnackbar(key)}>Dismiss</Button>
      ),
    });
  };

  return <button onClick={handleClick}>Show custom snackbar</button>;
}
  1. Using with class components:
import { withSnackbar } from 'notistack';

class MyComponent extends React.Component {
  handleClick = () => {
    this.props.enqueueSnackbar('Hello from class component!', {
      variant: 'warning',
    });
  };

  render() {
    return <button onClick={this.handleClick}>Show snackbar</button>;
  }
}

export default withSnackbar(MyComponent);

Getting Started

  1. Install the package:
npm install notistack @mui/material @emotion/react @emotion/styled
  1. Wrap your app with SnackbarProvider:
import { SnackbarProvider } from 'notistack';

function App() {
  return (
    <SnackbarProvider maxSnack={3}>
      {/* Your app components */}
    </SnackbarProvider>
  );
}
  1. Use the useSnackbar hook or withSnackbar HOC in your components to display snackbars.

Competitor Comparisons

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

Pros of Material-UI

  • Comprehensive UI component library with a wide range of pre-built components
  • Extensive documentation and community support
  • Highly customizable with theming capabilities

Cons of Material-UI

  • Larger bundle size due to its extensive feature set
  • Steeper learning curve for beginners
  • May require more configuration for specific use cases

Code Comparison

Material-UI example:

import Button from '@mui/material/Button';

function App() {
  return <Button variant="contained">Hello World</Button>;
}

Notistack example:

import { useSnackbar } from 'notistack';

function App() {
  const { enqueueSnackbar } = useSnackbar();
  return <button onClick={() => enqueueSnackbar('Hello World')}>Show snackbar</button>;
}

Summary

Material-UI is a comprehensive UI library offering a wide range of components and extensive customization options. It's well-suited for large-scale applications but may be overkill for simpler projects. Notistack, on the other hand, is focused specifically on snackbar notifications, making it a lightweight and easy-to-use solution for this particular use case. The choice between the two depends on the project's requirements and complexity.

React notification made easy 🚀 !

Pros of react-toastify

  • More customizable with a wider range of options for styling and behavior
  • Supports mobile-friendly touch gestures for dismissing notifications
  • Includes built-in CSS animations for smoother transitions

Cons of react-toastify

  • Larger bundle size, which may impact performance in smaller applications
  • Steeper learning curve due to more complex API and configuration options
  • Less seamless integration with Material-UI compared to notistack

Code Comparison

notistack:

import { useSnackbar } from 'notistack';

const { enqueueSnackbar } = useSnackbar();
enqueueSnackbar('This is a success message!', { variant: 'success' });

react-toastify:

import { toast } from 'react-toastify';

toast.success('This is a success message!', {
  position: toast.POSITION.TOP_RIGHT,
  autoClose: 3000,
});

Both libraries offer simple ways to display notifications, but react-toastify provides more granular control over positioning and timing out of the box. notistack's API is more concise and integrates seamlessly with Material-UI's theming system.

🍞 A toast notification system for react

Pros of react-toast-notifications

  • Simpler API with fewer configuration options, making it easier to get started
  • Built-in support for custom toast components without additional setup
  • Lightweight package with fewer dependencies

Cons of react-toast-notifications

  • Less flexible positioning options compared to notistack
  • Fewer built-in features, such as pause on hover or dismiss oldest
  • Less active maintenance and fewer recent updates

Code Comparison

react-toast-notifications:

import { useToasts } from 'react-toast-notifications'

const { addToast } = useToasts()
addToast('This is a toast message', { appearance: 'success' })

notistack:

import { useSnackbar } from 'notistack'

const { enqueueSnackbar } = useSnackbar()
enqueueSnackbar('This is a snackbar message', { variant: 'success' })

Both libraries offer similar basic usage, with slight differences in naming conventions. notistack uses "snackbar" terminology, while react-toast-notifications uses "toast". The API structure is similar, but notistack provides more advanced features and configuration options beyond this basic example.

Smoking Hot React Notifications 🔥

Pros of react-hot-toast

  • Lightweight and minimalistic design, resulting in a smaller bundle size
  • Customizable and flexible toast positioning system
  • Easy to use with a simple API and minimal setup required

Cons of react-hot-toast

  • Limited built-in styling options compared to notistack's extensive theming
  • Lacks some advanced features like pause on hover or resume on mouse leave
  • No built-in support for snackbars or more complex notification types

Code Comparison

react-hot-toast:

import { toast } from 'react-hot-toast';

toast('Hello World');
toast.success('Successfully created!');
toast.error('This is an error!');

notistack:

import { useSnackbar } from 'notistack';

const { enqueueSnackbar } = useSnackbar();
enqueueSnackbar('Hello World', { variant: 'default' });
enqueueSnackbar('Successfully created!', { variant: 'success' });
enqueueSnackbar('This is an error!', { variant: 'error' });

Both libraries offer simple ways to display notifications, but react-hot-toast provides a more straightforward API with less setup required. notistack, on the other hand, offers more customization options and integration with Material-UI, making it suitable for more complex applications.

Delightful and highly customisable React Component to notify your users

Pros of react-notifications-component

  • More customizable appearance and animations
  • Supports multiple notification types (success, error, warning, etc.)
  • Allows for custom content, including React components

Cons of react-notifications-component

  • Larger bundle size
  • Less integrated with Material-UI ecosystem
  • Requires more setup and configuration

Code Comparison

react-notifications-component:

import { Store } from "react-notifications-component";

Store.addNotification({
  title: "Success!",
  message: "Your action was completed",
  type: "success",
  container: "top-right",
  dismiss: {
    duration: 3000,
  },
});

notistack:

import { useSnackbar } from 'notistack';

const { enqueueSnackbar } = useSnackbar();
enqueueSnackbar('Your action was completed', { variant: 'success' });

Both libraries offer easy-to-use APIs for displaying notifications, but react-notifications-component provides more options for customization out of the box. notistack integrates more seamlessly with Material-UI and has a simpler API, making it quicker to implement for basic use cases. The choice between the two depends on the specific requirements of your project, such as the level of customization needed and the existing tech stack.

1,557

:postbox: A simple and customizable React notifications system

Pros of reapop

  • More customizable themes and styles out of the box
  • Supports multiple notification positions simultaneously
  • Includes built-in animations for notifications

Cons of reapop

  • Less active development and community support
  • More complex setup and configuration process
  • Fewer integrations with popular UI libraries

Code Comparison

reapop:

import { setUpNotifications } from 'reapop'

setUpNotifications({
  defaultProps: { position: 'top-right', dismissible: true }
})

notistack:

import { SnackbarProvider } from 'notistack'

<SnackbarProvider maxSnack={3}>
  {/* Your app components */}
</SnackbarProvider>

Both libraries offer easy-to-use APIs for displaying notifications, but notistack's implementation is more straightforward and requires less initial setup. reapop provides more granular control over notification appearance and behavior, while notistack focuses on simplicity and integration with Material-UI.

reapop's theming system is more extensive, allowing for greater customization of notification styles. However, notistack's simpler approach may be preferable for projects that don't require complex notification designs.

In terms of community support and ongoing development, notistack has an advantage with more frequent updates and a larger user base. This can be crucial for long-term project maintenance and issue resolution.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

notistack logo

Notistack: Display notifications with call of a function.

Easy to use, customizable, smooth transitions, stack and queue them up!

Table of Contents

Getting Started

Use your preferred package manager:

npm install notistack
yarn add notistack

Version guide

VersionNotes
v3.x.xLatest stable release. Standalone (i.e. not dependent on material-ui)
<= v2.0.8Requires Material-UI v5 as peer dependency. npm install notistack@2.0.8
<= 1.0.10Requires Material-UI <= v4 as peer dependency. npm install notistack@latest-mui-v4

How to use

Instantiate a SnackbarProvider component and start showing snackbars: (see docs for a full list of available props)

import { SnackbarProvider, enqueueSnackbar } from 'notistack';

const App = () => {
  return (
    <div>
      <SnackbarProvider />
      <button onClick={() => enqueueSnackbar('That was easy!')}>Show snackbar</button>
    </div>
  );
};

Alternatively, You can use useSnackbar hook to display Snackbars. Just remember to wrap your app inside of a SnackbarProvider to have access to the hook context:

import { SnackbarProvider, useSnackbar } from 'notistack';

// wrap your app
<SnackbarProvider>
  <App />
  <MyButton />
</SnackbarProvider>

const MyButton = () => {
  const { enqueueSnackbar, closeSnackbar } = useSnackbar();
  return <Button onClick={() => enqueueSnackbar('I love hooks')}>Show snackbar</Button>;
};

Online demo

Visit the documentation website to see all the examples.
Or play with a minimal working example: codesandbox

Contribution

Open an issue and your problem will be solved.

Author - Contact

Hossein Dehnokhalaji

Hossein Dehnokhalaji Instagram profile Hossein Dehnokhalaji Linkedin profile Hossein Dehnokhalaji email address

NPM DownloadsLast 30 Days