我想决定是否在某些过程后激活自动隐藏持续时间
使用挂钩管理状态的FC组件中的
<Snackbar
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center',
}}
open={open}
autoHideDuration={isLoading ? 500 : null}
onClose={(e: any, reason: string) => {
handleClose(e, reason);
}}
>
答案 0 :(得分:0)
您可以使用 state 这样实现:
class YourClass extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: false,
}
}
// some code that changes the state to *true*
<Snackbar
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center',
}}
open={open}
autoHideDuration={this.state.isLoading ? 500 : null}
onClose={(e: any, reason: string) => {
handleClose(e, reason);
}}
>
}