npm install --save react-snackbar-messages
or
yarn add react-snackbar-messages
Wrap your application within a SnackbarProvider
.
import { SnackbarProvider, useSnackbar } from 'react-snackbar-messages'
const ChildComponent = () => {
const snackbar = useSnackbar()
const showSnackbar = () => {
snackbar.add('Hello Snackbar!', {
appearance: 'success',
autoDismiss: true
})
}
return <button onClick={showSnackbar}>Show Snackbar</button>
}
const App = () => (
<SnackbarProvider>
<ChildComponent />
</SnackbarProvider>
)