title: How to increase quantity of the item if it is already added in shopping cart in React
body: <p>I am facing an issue with shopping cart. Unable to increase quantity of existing item in cart or add another item. On button click the addToCart function executes which takes a product.</p>
  
  <pre><code>const [cartItems, setCartItems] = useState([])
  
  const addToCart = product =&gt; {
      console.log(product) // here I am getting the entire product
      const index = cartItems.findIndex(item =&gt; item._id === product._id);
  
      if (index === -1) {
        const updateCart = cartItems.concat({
          ...product,
          quantity: 1
        });
        setCartItems(updateCart);
      } else {
        const updateCart = [...cartItems];
        updateCart[index].quantity += 1;
        setCartItems(updateCart);
      }
    };
  </code></pre>
  
  <p>I am getting only 1 quantity of product and if I add another product  or increase quantity, it overwrites.</p>