Modifying quantity

The editable quantity TextField rendered for each cart item allows the user to update the quantity for each product they are buying, and sets a minimum allowed value of 1.

mern-marketplace/client/cart/CartItems.js:

Quantity: <TextField          value={item.quantity}          onChange={this.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 state, and update the cart in localStorage using the helper method.

mern-marketplace/client/cart/CartItems.js:

handleChange = index => event => {    let cartItems = this.state.cartItems     if(event.target.value == 0){ cartItems[index].quantity ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.