【发布时间】:2020-10-16 12:38:41
【问题描述】:
我使用 react native 和 redux 创建了一个购物应用程序,我遇到了一个问题,当用户单击购买时,它应该在底部查看一个组件,该组件将显示总金额和查看购物车按钮,以及当用户从购物车中删除商品时购物车是空的,它应该关闭/状态设置为 false,但它不会消失。谁能告诉我怎么了,下面是我的代码 reducer.js
if (action.type === SHOW_CART) {
let addedItem = state.jeans.find((item) => item.id === action.id);
if (addedItem == 0) {
return {
...state,
show: console.log(state.showCart),
};
} else {
return {
...state,
show: console.log(action.showCart),
};
}
}
const initialstate = {
showChart: false,
}
这是我处理该功能的减速器
action.js
export const showCart = (id) => {
return {
type: SHOW_CART,
showCart: true,
id,
};
};
这是我的行为,我描述它的行为
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={() => RootNavigation.navigate("Cart")}
>
View Cart
</Text>
</View>
</View>
) : null}
</View>
const mapStateToProps = (state) => {
return {
total: state.clothes.total,
show: state.clothes.show,
};
};
这就是我使用减速器的功能
【问题讨论】:
标签: javascript reactjs react-native react-redux