snackstack v1.3.2
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
:
import { SnackProvider } from 'snackstack';
ReactDOM.render(
<SnackProvider>
<App />
</SnackProvider>,
document.getElementById('root')
);
If you're using MuiThemeProvider
make sure that you place the SnackProvider
inside of it.
withSnacks
The withSnacks
HOC injects the enqueueSnack
and closeSnack
function into your component's props
:
import { withSnacks } from 'snackstack';
class ExampleComponent extends React.Component {
onEnqueueClick = () => {
const { enqueueSnack } = this.props;
enqueueSnack({ message: 'Hello World', key: 'key123' });
};
onCloseClick = () => {
const { closeSnack } = this.props;
closeSnack('key123');
};
render() {
return (
<div>
<button onClick={this.onEnqueueClick}>Enqueue</button>
<button onClick={this.onCloseClick}>Close</button>
</div>
);
}
}
export default withSnacks(ExampleComponent);
useSnacks
The useSnacks
Hook returns an array containing the enqueueSnack
and closeSnack
function:
import { useSnacks } from 'snackstack';
const ExampleComponent = () => {
const [enqueueSnack, closeSnack] = useSnacks();
const onEnqueueClick = () => {
enqueueSnack({ message: 'Hello World', key: 'key123' });
};
const onCloseClick = () => {
closeSnack('key123');
};
return (
<div>
<button onClick={onEnqueueClick}>Enqueue</button>
<button onClick={onCloseClick}>Close</button>
</div>
);
};
export default ExampleComponent;
If you're unfamiliar with Hooks I suggest this article as an introduction.
Documentation
Not yet available
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago