redux useEffect内部状态更改后分派操作

nr9pn0ug  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(108)

我想在useEffect中的状态更改后调度操作

React.useEffect(() => {
    let timer = setInterval(() => {
      setCurrTime(activeCallTime());
      /**
       @todo:dispatch currtime action  
      **/
    }, 1000);
    
    return () => clearInterval(timer);
  }, [props.startTime]);
bis0qfac

bis0qfac1#

请尝试此解决方案

React.useEffect(() => {
        let timer = setInterval(() => {
          setCurrTime(activeCallTime());
        }, 1000);
        
        return () => clearInterval(timer);
      }, [props.startTime]); 

React.useEffect(() => {
    dispatch the action  
 }, [currTime]);
vdzxcuhz

vdzxcuhz2#

React.useEffect(() => {
    let timer = setInterval(() => {
     let temp = activeCallTime() 
     setCurrTime(temp);
      //dispatch temp
    }, 1000);
    
    return () => clearInterval(timer);
  }, [props.startTime]);

相关问题