autoHideDuration is not working in Snackbar @material-ui
·
Answer a question
I have used Snackbar from Material-ui to display an alert. I want to hide that Snackbar automatically after 5 seconds but autoHideDuration is not working .
<Snackbar
autoHideDuration={3000}
open={true}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id"> Message </span>}
/>
See screenshot
Answers
You also have to implement the onClose method of the Snackbar component in order to make the timeout work.
Let's say the open status of the Snackbar is in your component state:
<Snackbar
autoHideDuration={3000}
open={this.state.open}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id"> Message </span>}
onClose={() => this.setState({open: false})}
/>
更多推荐
所有评论(0)