AppState和Redux工具包在Android上

发布于 2025-02-08 20:18:57 字数 624 浏览 1 评论 0原文

当前,我正在使用AppState来知道该应用何时返回活动状态,在其中,我在内部进行了一个API调用,请参见Redux,请参见下面的Cold。

useEffect(() => {
 const subscription = AppState.addEventListener("change", (nextAppState) => {
 if (
 appState.current.match(/inactive|background/) &&
 nextAppState === "active"
      ) {
 getTimes();
 dispatch(getLocation());
 dispatch(getCity());
      }

 appState.current = nextAppState;
 setAppStateVisible(appState.current);
    });

 return () => {
 subscription.remove();
    };
  }, []);

它在iPhone上正常工作,但是当我将其部署到Android时,API调用会不断打电话,并且如果我评论Redux呼叫并将其重新部署到Android手机时,请永远不会停止,一切正常,并且不会保持刷新。

current I'm using AppState to know when the app is coming back to the active state and inside there I'm making an API call with redux see cold below.

useEffect(() => {
 const subscription = AppState.addEventListener("change", (nextAppState) => {
 if (
 appState.current.match(/inactive|background/) &&
 nextAppState === "active"
      ) {
 getTimes();
 dispatch(getLocation());
 dispatch(getCity());
      }

 appState.current = nextAppState;
 setAppStateVisible(appState.current);
    });

 return () => {
 subscription.remove();
    };
  }, []);

It works fine on an iPhone but when I deploy it to an android the API calls keep getting called and never stop if I comment out the redux call and redeploy it to an android phone everything works fine and it doesn't keep refreshing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文