首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redux减速器没有返回整个状态。

Redux减速器没有返回整个状态。
EN

Stack Overflow用户
提问于 2020-07-21 06:42:00
回答 1查看 67关注 0票数 0

我是redux的新手,我的问题是当我分派操作时,它会转到还原程序,但是状态没有更新。

,这是我的初始状态

代码语言:javascript
复制
   const initialState ={
    cart :[ ],
    Products:[
        {
            id:"1",
            title:"Realme 3 pro",
            image:{
                img1:"https://www.monotain.com/wp-content/uploads/2019/12/realme-5-pro.jpg",
                img2:"https://static.techspot.com/images/products/2019/smartphones/org/2019-05-20-product-7.jpg"
            },
           
            price:"10000",
            details:"Take photography a notch higher with the Realme 3 Pro as it comes with a 25 MP AI Selfie Camera and 16 MP + 5 MP Rear Camera with Sony IMX519 Sensor. The Qualcomm Snapdragon 710 AIE, multi-core AI Engine and Adreno 616 GPU redefine your smartphone experience.",
            seller:"Cloudtail India",
            quantity:"0"
    
    
        }
       
       
    
     ]
     
}

**这是我的减速机,它正在处理这个动作**

代码语言:javascript
复制
         case UPDATE_QUANTITY:
              
                return{
                    ...state,
                    cart:state.cart.map((product,i) =>
                    {
                        if(i === (action.product.id-1))
                       {
                           return{product.quantity = action.qty.toString()}
                         

                       }
                           return product
                       
                        
                    })
                } 

其他还原器运行良好,并返回正确的状态,但当我分派此操作时,我的状态没有更新.If,因此需要对代码.Please指定进行任何改进。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-21 06:46:12

您需要从地图返回:

代码语言:javascript
复制
case UPDATE_QUANTITY:
  return {
    ...state,
    cart: state.cart.map((product) => {
      if (product.id === action.product.id) {
        return {...product, quantity: action.qty.toString()}
      }
      return product;
    })
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63008799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档