第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React Native,redux 函數(shù)在更新后不會恢復到原始狀態(tài)

React Native,redux 函數(shù)在更新后不會恢復到原始狀態(tài)

慕尼黑5688855 2023-05-19 18:10:57
當用戶將商品添加到購物車時,我創(chuàng)建了一個功能來查看每個屏幕下方的購物車詳細信息,當用戶刪除功能時,購物車詳細信息將再次隱藏,但是當我從購物車中刪除商品時,購物車詳細信息沒有隱藏,有人可以告訴我出了什么問題,下面是我的代碼減速器 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: [],}這是我執(zhí)行該功能的 redux 代碼,addItems 是我的購物車,它是空白數(shù)組行動export const showCart = (id) => {  return {    type: SHOW_CART,    showCart: true,    id,  };};這是我的行動查看購物車  {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}這是我的查看購物車詳細信息,當用戶將商品添加到購物車時我會顯示購物車詳細信息有人可以幫忙嗎
查看完整描述

2 回答

?
largeQ

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,

      };

    }

  }


查看完整回答
反對 回復 2023-05-19
?
守著一只汪

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,

  };

};



查看完整回答
反對 回復 2023-05-19
  • 2 回答
  • 0 關注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號