Skip to content

Instantly share code, notes, and snippets.

@kofno
Created December 14, 2018 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kofno/7674077ee38b2c98f9721275e24dc5e6 to your computer and use it in GitHub Desktop.
Save kofno/7674077ee38b2c98f9721275e24dc5e6 to your computer and use it in GitHub Desktop.
Snackbar Alert component that reacts to changes in a MobX store
// -- 1 --
import Snackbar from '@material-ui/core/Snackbar';
import { observer } from 'mobx-react';
import React from 'react';
import AlertContent from './content';
import alertsStore from './store';
const Alerts = () => {
// -- 2 --
return alertsStore.current.cata({
// -- 4 --
Just: alert => (
<Snackbar
// -- 5 --
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
open={alert.display}
onClose={alertsStore.hide}
onExited={alertsStore.process}
autoHideDuration={6000}
>
// -- 6 --
<AlertContent alert={alert} />
</Snackbar>
),
// -- 3 --
Nothing: () => <></>,
});
};
// -- 7 --
export default observer(Alerts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment