client/src/preview/route/digitaltwins/Snackbar.tsx
import * as React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Snackbar from '@mui/material/Snackbar';
import Alert from '@mui/material/Alert';
import { RootState } from 'store/store';
import { hideSnackbar } from 'preview/store/snackbar.slice';
const CustomSnackbar: React.FC = () => {
const dispatch = useDispatch();
const { open, message, severity } = useSelector(
(state: RootState) => state.snackbar,
);
const handleClose = () => {
dispatch(hideSnackbar());
};
return (
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
<Alert onClose={handleClose} severity={severity}>
{message}
</Alert>
</Snackbar>
);
};
export default CustomSnackbar;