【问题标题】:React Adding delay to apply a class in the stateReact 添加延迟以在状态中应用类
【发布时间】:2020-06-11 09:54:05
【问题描述】:

我需要延迟申请新课程。

这是我的情况

const [done, setDone] = useState<boolean>(false);

在一个方法里面,我有这个

const myMethod= () => {
  ....
  ....
  setDone(true)
}

在我的按钮中,当done 为真时,我希望课程延迟,所以它不会被禁用

  <Button 
    disabled={!complete}  
  </Button>

【问题讨论】:

标签: javascript reactjs react-redux material-ui react-hooks


【解决方案1】:

我认为你可以使用setTimeout

const myMethod= () => {
  ....
  ....
  setTimeout(() => {
     setDone(true);
  }, 2000); // setDone will be called after 2s
}

【讨论】:

    猜你喜欢
    • 2020-11-22
    • 2020-02-07
    • 2023-01-14
    • 2022-09-26
    • 2021-03-12
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    • 2018-01-19
    相关资源
    最近更新 更多