AppState和Redux工具包在Android上
当前,我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论