2 回答

TA貢獻2039條經(jīng)驗 獲得超8個贊
你應該比較長度,你目前正在直接比較數(shù)組,所以它也會去錯誤的路徑,所以先改變它。
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,
};
}
}

TA貢獻1872條經(jīng)驗 獲得超4個贊
在視圖購物車中,
{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")}
>
View Cart
</Text>
</View>
</View>
) : null}
const mapStateToProps = (state) => {
return {
total: state.clothes.total,
show: state.clothes.show,
items: state.clothes.addedItems,
};
};
添加回答
舉報