Javascript 反应本机,如何再次使redux状态为false

Javascript 反应本机,如何再次使redux状态为false,javascript,reactjs,react-native,react-redux,Javascript,Reactjs,React Native,React Redux,我创建了一个查看购物车,在其中我显示总价和查看购物车按钮,当我添加项目时,它使条件为真,并在每个屏幕下方显示该购物车,但当我单击查看购物车时,它不会再次使其为假,我如何才能做到这一点?有人能查一下我的密码并告诉我吗。下面是我的代码 Viewcart.js <View> {this.props.show && this.props.items.length > 0 ? ( <View style={styles.total

我创建了一个查看购物车,在其中我显示总价和查看购物车按钮,当我添加项目时,它使条件为真,并在每个屏幕下方显示该购物车,但当我单击查看购物车时,它不会再次使其为假,我如何才能做到这一点?有人能查一下我的密码并告诉我吗。下面是我的代码

Viewcart.js

<View>
        {this.props.show && this.props.items.length > 0 ? (
          <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={() => {
                  RootNavigation.navigate("Cart");
                  this.props.show;
                }}
              >
                View Cart
              </Text>
            </View>
          </View>
        ) : null}
      </View>
const mapStateToProps = (state) => {
  return {
    show: state.clothes.show,
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    showCart: () => dispatch(showCart()),
  };
};
action.js

export const showCart = (id) => {
  return {
    type: SHOW_CART,
    showCart: true,
    id,
  };
};

根据聊天记录,要求在退出屏幕时切换,因此最简单的方法是使用生命周期方法

要隐藏,请使用componentDidMount

componentDidMount(){
 this.props.showCartOff(); 
}
显示使用组件的步骤

componentWillUnmount(){
  this.props.showCart();
}

我认为您需要编写一个
hideCart
函数,并在组件中的
onPress
函数中触发它,如果
show
状态为true,我尝试了,但它隐藏了该组件,但也清除了cartI使用的操作
export const showCartOff=()=>{return type:show_CARTOFF,isCart:true}
然后在reducer`if(type==ShOW_CARTOFF){return{…state,isCart:action.Cart}}`初始状态
isCart:true
在export const showCart=(id)={}将其设置为true,在哪里将其设置为false?在初始状态下
componentWillUnmount(){
  this.props.showCart();
}