Javascript React Native Redux不更新布尔值

Javascript React Native Redux不更新布尔值,javascript,reactjs,react-native,redux,Javascript,Reactjs,React Native,Redux,我为我的购物应用程序创建了一个布尔状态,在该状态下,当用户单击“购买”按钮时,它应该将该状态设置为true,并在容器中显示购物车总数,但它不起作用 下面是我的代码: 减速器: if(action.type==SHOW\u CART){ 返回{ ……国家, show:action.showCart, }; 常量初始状态={ 秀:假,, } 这是我的减速器的初始状态: export const showCart = () => { return { type: SHOW_CART

我为我的购物应用程序创建了一个布尔状态,在该状态下,当用户单击“购买”按钮时,它应该将该状态设置为
true
,并在容器中显示购物车总数,但它不起作用

下面是我的代码:

减速器:

if(action.type==SHOW\u CART){
返回{
……国家,
show:action.showCart,
};
常量初始状态={
秀:假,,
}
这是我的减速器的初始状态:

export const showCart = () => {
  return {
    type: SHOW_CART,
    showCart: true,
  };
};
这就是我的行动:


{
this.props.addToCart(item.id);
this.props.showCart();
}}
>
买一次
常量mapStateToProps=(状态)=>{
返回{
商品:国家服装牛仔裤,
};
};
const mapDispatchToProps=(调度)=>{
返回{
addToCart:(id)=>调度(addToCart(id)),
showCart:()=>分派(showCart()),
};
};
在这段代码中,我使用了一个平面列表,在平面列表中,我使用
onPress
来显示购物车容器并分派我的操作

应用程序

导出默认函数App(){
返回(
);
}
ViewCart.js

  <View>
        {this.props.show ? (
          <View style={styles.total}>
            <Text style={styles.totaltext}>Total:</Text>
            <Text style={styles.priceTotal}>{this.props.total}</Text>
            <View style={styles.onPress}>
              <Text
                style={styles.pressText}
                onPress={() => this.props.navigation.navigate("Cart")}
              >
                View Cart
              </Text>
            </View>
          </View>
        ) : null}
      </View>
const mapStateToProps = (state) => {
  return {
    total: state.clothes.total,
    show: state.clothes.show,
  };
};

export default connect(mapStateToProps)(ViewChart);

{这是道具秀吗(
总数:
{this.props.total}
this.props.navigation.navigate(“购物车”)}
>
查看购物车
):null}
常量mapStateToProps=(状态)=>{
返回{
总计:state.counts.total,
秀:state.counts.show,
};
};
导出默认连接(MapStateTops)(ViewChart);
在App.js中,我添加了查看购物车的conatiner,当用户单击“购买”时应该会显示它 在视图中,我发现错误
未定义不是一个对象(评估“\u this.props.navigation.navigate”)
更改

this.props.showCart;


this.props.showCart;应该是这个.props.showCart();未工作抛出一个错误
\u this.props.showCart不是一个函数。
addToCart工作吗?是的,它工作showchar应该是showCart已经抛出并且错误
\u this.props.showCart不是一个函数。
不是“showCart”而是“showChart”正如您在代码中所描述的,请检查我现在更新的代码错误在ViewCart.js中,并且它在cart组件中显示ViewCart
this.props.showCart;
this.props.showChart();