Created
December 14, 2018 20:56
-
-
Save kofno/7674077ee38b2c98f9721275e24dc5e6 to your computer and use it in GitHub Desktop.
Snackbar Alert component that reacts to changes in a MobX store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -- 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