Skip to content
Advertisement

React Redux how to update product quantity in shopping cart

I have a store in redux. There is 2 arrays, womanProducts and cartProducts

JavaScript

Then I dispatch cartProducts and add women products to shopping cart (Case “ADD_PRODUCTS” to add products in cart and “REMOVE_FROM_CART” to remove items from cart) it’s working well, but “INCREMENT_PRODUCT” not working

JavaScript

But now I need to increment and decrement prodcuts in cart by clicking button

Cart Component:

JavaScript

And function to increment product

JavaScript

Advertisement

Answer

First you should change your payload. It needs item id to determine which item you are incrementing

JavaScript

Now, You can map the cart products; if item id is same with cart item id then increment or just return the item

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement