我正在使用Material UI(react)构建网站,并且正在使用小吃店。我想通过特定的计时器延迟其显示。我该如何实现?
我尝试过
sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
handleSubmit = (newTask) => {
this.setState({ modalOpen: false}, () => {this.sleep(5000)})
this.setState({ snackBarOpen: true });
}
<Snackbar autoHideDuration={5000} className={classes.snackbar} open={this.state.snackBarOpen} anchorOrigin={{vertical: 'bottom', horizontal: 'left'}}>
<SnackbarContent message="Task Creation Successful." />
</Snackbar>