React Snackbar Alert uses the Context API and Hooks. This means it requires React 16.8.0 or newer.
This package requires react
, react-dom
, and styled-components
to be installed in your project.
$ npm install --save react react-dom styled-components
$ npm install --save react-snackbar-alert
SnackbarProvider
component and the wrapComponent
helperSnackbarProvider
and pass any configuration to itwrapComponent
helper. This will give it a createSnackbar
prop.createSnackbar
to create snackbarsimport React from 'react';
import { SnackbarProvider, wrapComponent } from 'react-snackbar-alert';
export default function BaseExample() {
return (
<SnackbarProvider>
<Container />
</SnackbarProvider>
);
}
const Container = wrapComponent(function({ createSnackbar }) {
function showSnackbar() {
createSnackbar({
message: 'Hello Snackbar!'
});
}
return (
<div>
<button onClick={showSnackbar}>Show Snackbar</button>
</div>
);
});