代码之家  ›  专栏  ›  技术社区  ›  user938363

需要返回后导航.goback()?

  •  0
  • user938363  · 技术社区  · 3 年前

    if (condition_met) {
        setTimeout(()=> {
         navigation.goBack();
         return;  //<<==needed after navigation or useless/never executed?
       }, 1000);
     }
     //do something else if above condition not met.
    
    2 回复  |  直到 3 年前
        1
  •  1
  •   eamanola    3 年前

    调用的函数 setTimeout 之后执行 // do something else .

    移动 return 设置超时

    if (condition_met) {
      setTimeout(()=> {
        navigation.goBack();     
      }, 1000);
    
      return;  //condition met stop executing code further
    }
    
    //do something else if above condition not met.
    
        2
  •  1
  •   Andrew Ogaga    3 年前

    通常建议在关闭组件时调用useEffect的返回函数中处理此类效果。

        useEffect(() => {
        return () => {
          // cleanup code codes here
        };
      },[]);
    

    这会在比赛结束后起作用 navigation.goBack()