I have an array that contains <SnackBar>
elements:
const [snackbars,setSnackbars]=useState([
<ReactSnackBar Show={true}>
Snackbar 1
<Icon onClick={snackbars.pop()}/>
</ReactSnackBar>,
...
]}
I want to click on the <Icon/>
, to remove this current snackbar, so that the next snackbar becomes visible.
But this doesn't work with the error
ReferenceError: can't access lexical declaration `snackbars' before initialization
If I use a helper function inside the onClick
it's the same.
Are there any suggestions on how to solve that?