Adding to cart

The AddToCart component in client/Cart/AddToCart.js takes a product object and a CSS styles object as props from the parent component it is added to. For example, in MERN Marketplace, it is added to a Product view as follows:

<AddToCart cartStyle={classes.addCart} item={this.state.product}/>

The AddToCart component itself displays a cart icon button depending on whether the passed item is in stock or not:

For example, if the item quantity is more than 0, the AddCartIcon is displayed, otherwise the DisabledCartIcon is rendered.

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

{this.props.item.quantity >= 0 ?  <IconButton color="accent" ...

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.