diff --git a/src/ProductList.jsx b/src/ProductList.jsx index 7682c04fc4..c11dfe589c 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -1,9 +1,13 @@ import React, { useState, useEffect } from 'react'; import './ProductList.css' import CartItem from './CartItem'; +import { addItem } from './CartSlice'; + + function ProductList({ onHomeClick }) { const [showCart, setShowCart] = useState(false); - const [showPlants, setShowPlants] = useState(false); // State to control the visibility of the About Us page + const [showPlants, setShowPlants] = useState(false); + const [addedToCart, setAddedToCart] = useState({}); const plantsArray = [ { @@ -252,6 +256,18 @@ function ProductList({ onHomeClick }) { e.preventDefault(); setShowCart(false); }; + + const handleAddToCart = (product) => { + dispatch(addItem(product)); + + setAddedToCart((prevState) => ( + { + ...prevState, + [product.name]: true, + } + )); + }; + return (