snackstack
Easy-to-use extension of Material-UI, which allows the stacking of Snackbar notification messages.
Table of Contents
Installation
Method | Command |
---|---|
npm | npm install snackstack |
yarn | yarn add snackstack |
Getting started
Wrap all components, which should be able to enqueue or close Snackbar Notifications, in a SnackProvider
:
; ReactDOM;
If you're using MuiThemeProvider
make sure that you place the SnackProvider
inside of it.
Handling Notifications
withSnacks
The withSnacks
HOC injects the enqueueSnack
and closeSnack
function into your component's props
:
import withSnacks from 'snackstack'; Component { const enqueueSnack = thisprops; ; }; { const closeSnack = thisprops; ; }; { return <div> <button =>Enqueue</button> <button =>Close</button> </div> ; } ExampleComponent;
useSnacks
The useSnacks
Hook returns an array containing the enqueueSnack
and closeSnack
function:
import useSnacks from 'snackstack'; const ExampleComponent = const enqueueSnack closeSnack = ; const handleEnqueueClick = ; ; const handleCloseClick = ; ; return <div> <button =>Enqueue</button> <button =>Close</button> </div> ;; ;
If you're unfamiliar with Hooks I suggest this article as an introduction.
Documentation
Not yet available