【发布时间】:2021-12-29 07:19:55
【问题描述】:
我不知道这是否适合这个地方。但是是的,我的 react native expo 应用程序遇到了这个问题。这是一个电子商务应用程序。最初,我正在获取用户购物车项目并将它们存储在 redux 状态。以及当用户继续将新商品添加到购物车时。然后我调用一个 API 来添加和检索新的购物车项目,并使用新的记录集更新 redux 状态。现在的问题是。这会重新加载整个应用程序。并返回主屏幕。
我不知道它为什么会这样做。我想知道是否有办法阻止这种重定向?
更新:::: 我只是注意到在尝试更新 redux 时它在主屏幕上也是如此。它不断刷新。
从购物车中获取商品的功能
async getCartItems(){
this.setState({
refreshing:true
})
const buyer_id = this.props.data?.userRecords?.id;
globalFunctions.getSecureValue(my_user_token) //geting token from the securestorage
.then((response) =>{
if (response) {
vendorServices.getItemCart(buyer_id,response) //getting the user cart items
.then((data) =>{
if (data) {
this.props.addCartCount(data.data.length); //updating the redux state for cart counter
this.props.addToCart(data.data); //updating the redux state for cart items records
if(this._ismounted){
this.setState({
refreshing:false
})
}
}
})
.catch((error) =>{
console.log(error)
})
}
})
}
这里的重点是。为什么整个应用程序必须在 redux 状态更改时重新加载?有什么办法可以阻止这个吗? 请帮忙。
【问题讨论】:
-
您能否编辑问题以显示问题所在的代码?
-
已更新。请检查。是的,我的主要观点是。我想在 redux 状态更改时阻止应用重新加载。
-
会不会是你正在改变应用程序的完整状态,所以这就是为什么要重新加载?
-
可能是这样,请问如何停止直接变异。
标签: react-native redux expo