autoHideDuration не работает с изменением состояния - PullRequest
0 голосов
/ 22 мая 2019

Я хочу решить, активировать ли я длительность автоматического скрытия после некоторого процесса

в компоненте FC с использованием хуков для управления состоянием

 <Snackbar
        anchorOrigin={{
          vertical: 'bottom',
          horizontal: 'center',
        }}
        open={open}
        autoHideDuration={isLoading ? 500 : null}
        onClose={(e: any, reason: string) => {
          handleClose(e, reason);
        }}
>

1 Ответ

0 голосов
/ 22 мая 2019

Этого можно достичь, используя состояние , например:

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);
    }}
  >

}
...