I am facing an issue with my snackBar and alert components from MUI. I am trying to close the alert using a function or by clicking on the crossIcon, but it's not working as expected. I have used code examples from MUI, but still can't figure out why it's not functioning properly. Any suggestions or ideas would be greatly appreciated, as I am new to React and MUI.
https://i.sstatic.net/Cc7OQ.png
import { useState } from 'react';
import CloseIcon from '@mui/icons-material/Close';
import { Alert, AlertTitle, IconButton, Snackbar, Typography } from '@mui/material';
interface InfoMessageProps {
open: boolean;
}
export const InfoMessage = ({ open }: InfoMessageProps) => {
const [openMessage, setOpenMesage] = useState(false);
const handleCloseMessage = (): void => {
setOpenMesage(false);
};
return (
<Snackbar
open={open}
autoHideDuration={4000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
onClose={handleCloseMessage}
>
<Alert
sx={{
width: '487px',
height: '104px',
paddingTop: '20px',
paddingLeft: '20px',
backgroundColor: '#FDFDFD',
}}
icon={false}
action={(
<IconButton
aria-label="close"
color="inherit"
size="small"
onClick={handleCloseMessage}
>
<CloseIcon fontSize="inherit" />
</IconButton>
)}
>
<AlertTitle sx={{ paddingRight:'80px' }}>
<Typography variant='headings.h4'>title</Typography>
</AlertTitle>
<Typography variant='captions.default'>Insert message here</Typography>
</Alert>
</Snackbar>
);
};