I'm building an online store with react using context api...Now, I'm facing a particular issue with total price in cart.

THE PROBLEM: I was successful getting the total price of items in cart using reduce but if I remove an item from cart, the total price increases instead of decreasing.

I made a new state named totalPrice then in useEffect, I setTotalPrice to (productsPrice.reduce((a, b) => a + b, 0))
productsPrice is an array that consist of all the prices of products added to cart

Any help??

```
 useEffect(() => {
      //Add new products in cart price to productPrice state array
      cartProducts.map((prod) => {
        return setProductPrice([...productPrice, prod.price]);
      });

      //Calculate all price in product price array and set the total price to TotalProductPrice state
      function getPrice() {
        const total = productPrice.reduce((acc, curr) => acc + curr, 0);
        setTotalProductPrice(total);
      }
      getPrice();
    }, [cartProducts]);

```