April 2020
Intermediate to advanced
716 pages
18h 55m
English
Each cart item displayed in the cart view will contain an editable TextField that will allow the user to update the quantity for each product they are buying, with a minimum allowed value of 1, as shown in the following code.
mern-marketplace/client/cart/CartItems.js:
Quantity: <TextField value={item.quantity} onChange={handleChange(i)} type="number" inputProps={{ min:1 }} InputLabelProps={{ shrink: true, }} />
When the user updates this value, the handleChange method is called to enforce the minimum value validation, update the cartItems in the state, and update the cart in localStorage using a helper method. The handleChange method is defined as follows.
mern-marketplace/client/cart/CartItems.js:
const handleChange = ...
Read now
Unlock full access