notistack

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

Github星跟踪图

notistack

npm downloads
npm version
npm version

Notistack is a Snackbar library which makes it extremely easy to display notifications on your web apps. It is highly customizable and enables you to stack snackbars/toasts on top of one another. See demos for more info.

Play with online demo here, Stacking behaviour, Dismiss oldest when reached maxSnack (3 here), ---, ---, , , Table of Contents

--

Getting Started

Use your preferred package manager:

npm install notistack
yarn add notistack 

How to use

1: Wrap your app inside a SnackbarProvider component: (see docs for a full list of available props)

Note: If you're using material-ui ThemeProvider, make sure SnackbarProvider is a child of it.

import { SnackbarProvider } from 'notistack';

<SnackbarProvider maxSnack={3}>
    <App />
</SnackbarProvider>

2: Export any component that needs to send notification using withSnackbar. By doing this, you'll have access to methods enqueueSnackbar and closeSnackbar, where the former can be used to send snackbars.

import { withSnackbar } from 'notistack';

class MyComponent extends Component {
  handleNetworkRequest = () => {
     fetchSomeData()
        .then(() => this.props.enqueueSnackbar('Successfully fetched the data.'))
        .catch(() => this.props.enqueueSnackbar('Failed fetching data.'));
  };

  render(){
     //...
  };
  
};

export default withSnackbar(MyComponent);

Online demo

You can see the online demo and experiment all the possible configurations here.
Or see the code for a minimal working example: codesandbox

Documentation

Visit the documentation website

Redux and Mobx support:

notistack is compatible with state management libraries such as Redux and Mobx. See notistack documentation for more info.

Contribution

Open an issue and your problem will be solved.

Notes

Material Design guidelines suggests that only one snackbar should be displayed at a time. But I liked to stack them. ? So I made notistack. But if you'd like to stick to the guidelines, you can set maxSnack to 1 and just take advantage of enqueueSnackbar function.

Author - Contact

Hossein Dehnokhalaji



主要指标

概览
名称与所有者iamhosseindhv/notistack
主编程语言TypeScript
编程语言JavaScript (语言数: 2)
平台
许可证Other
所有者活动
创建于2018-08-04 21:05:47
推送于2025-01-18 06:39:52
最后一次提交2025-01-18 06:38:49
发布数66
最新版本名称v3.0.2 (发布于 2025-01-18 06:38:49)
第一版名称v0.4.3 (发布于 )
用户参与
星数4k
关注者数22
派生数300
提交数515
已启用问题?
问题数436
打开的问题数51
拉请求数99
打开的拉请求数10
关闭的拉请求数74
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?