React Native, redux function not going to original state after updating

I created a function to view cart details below every screen when a user add a item to cart and when user remove function cart details will hide again, but when I remove item from cart, cart details not hidding, can someone tell me what’s wrong, below is my code

reducer

 if (action.type === SHOW_CART) {
    let addedItem = state.addedItems;
    if (addedItem === 0) {
      console.log(addedItem);
      return {
        ...state,
        show: state.showCart,
      };
    } 
  } 


const initialstate = {
  showChart: false,
  addedItems: [],
}

It’s my redux code where I’m performing that function, addItems is my cart which is blank array

action

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

Here is my action

ViewCart

  {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={() => RootNavigation.navigate("Cart")}
              >
                View Cart
              </Text>
            </View>
          </View>
        ) : null}

Here is my view cart detail where I showing cart details when user add item to cart can someone please help

Answer

You should compare the length, you are currently comparing the array directly so it would also go to the false path, so change that first.

if (action.type === SHOW_CART) {
    let addedItem = state.addedItems;
    if (addedItem.length === 0) {
      console.log(addedItem);
      return {
        ...state,
        show: state.showCart,
      };
    } else {
      return {
        ...state,
        show: action.showCart,
      };
    }
  }