我越来越无法在本机应用程序中的未安装组件错误上执行React状态更新,我已经通过了几种无法解决问题的可用解决方案 请帮助我了解我在这里做错了什么,
这是我在reducer中尝试过的
const Home = (dispatch) => {
let isUnmount = false;
return async () => {
try {
const response = await Server.get("/user/home");
if (!isUnmount) {
if (response.data.flag == true) {
dispatch({ type: "StoreData", payload: response.data.data });
} else {
dispatch({
type: "addError",
payLoad: "Something went wrong please try again",
});
}
}
} catch (error) {
dispatch({
type: "addError",
payLoad: "Something went wrong please try again",
});
}finally{
isUnmount = true;
}
};
};
和组件useEffect
useEffect(() => {
let isUnmount = false;
if (!isUnmount) {
Home();
}
const listner = navigation.addListener("didFocus", () => {
if (!isUnmount) {
Home();
}
});
return () => {
listner.remove();
isUnmount = true;
};
}, []);