Notistack

Highly customizable notification snackbars (toasts) that can be stacked on ...

README

notistack logo


[Notistack](https://notistack.com) is a notification 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.

Visit documentation website for demos.
npm version npm downloads package license





StackingDismiss
------


Table of Contents
--


Getting Started

Use your preferred package manager:
  1. ```
  2. npm install notistack
  3. yarn add notistack
  4. ```

If you're using Material-UI version 4.x.x or lower, download a compatible version of notistack using:
  1. ```
  2. npm install notistack@latest-mui-v4
  3. yarn add notistack@latest-mui-v4
  4. ```

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.
  1. ``` js
  2. import { SnackbarProvider } from 'notistack';

  3. <SnackbarProvider maxSnack={3}>
  4.     <App />
  5. </SnackbarProvider>

  6. ```


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.

  1. ``` js
  2. import { withSnackbar } from 'notistack';

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

  9.   render(){
  10.      //...
  11.   };

  12. };

  13. export default withSnackbar(MyComponent);
  14. ```

2 (alternative): You can use useSnackbar hook in your functional components as well.

  1. ``` js
  2. import { useSnackbar } from 'notistack';

  3. const MyButton = () => {
  4.     const { enqueueSnackbar, closeSnackbar } = useSnackbar();

  5.     const handleClick = () => {
  6.         enqueueSnackbar('I love hooks');
  7.     };

  8.     return (
  9.         <Button onClick={handleClick}>Show snackbar</Button>
  10.     );
  11. }
  12. ```

Online demo

**Visit [`documentation website`](https://notistack.com/examples) to see all the demos.**
Or play with a minimal working example: [codesandbox](https://codesandbox.io/s/github/iamhosseindhv/notistack/tree/master/examples/simple-example??hidenavigation=1&module=%2FApp.js)


Redux and Mobx support:

notistack is compatible with state management libraries such as Redux and Mobx.

Contribution

Open an issue and your problem will be solved.


Author - Contact

Hossein Dehnokhalaji

Hossein Dehnokhalaji Instagram profileHossein Dehnokhalaji Linkedin profileHossein Dehnokhalaji email address