Skip to content

Commit

Permalink
Merge pull request #477 from Vishesh-Tripathi/cartItem
Browse files Browse the repository at this point in the history
Fix for CartItems number Update issue
  • Loading branch information
harshalhonde21 authored Jul 24, 2024
2 parents 95ffd4e + 0f58b4a commit 2d3fd4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Frontend/src/Components/CartContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createContext, useContext, useState } from 'react';
const CartContext = createContext();

export const CartProvider = ({ children }) => {
//changes
const [cart, setCart] = useState([]);
const [userData, setUserData] = useState(''); // Add user data state
const addToCart = (product) => {
Expand Down Expand Up @@ -36,6 +37,7 @@ export const CartProvider = ({ children }) => {
<CartContext.Provider
value={{
cart,
setCart,
addToCart,
removeFromCart,
incrementQuantity,
Expand Down
4 changes: 4 additions & 0 deletions Frontend/src/Pages/Cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import AddIcon from "@mui/icons-material/Add";
import RemoveIcon from "@mui/icons-material/Remove";
import { useNavigate } from "react-router-dom";
import toast from "react-hot-toast";
import { useCart } from "../Components/CartContext";

const Cart = () => {
const context = useCart()
const {cart,setCart} = context;
const navigate = useNavigate();
const [error, setError] = useState(null);
const [cartItems, setCartItems] = useState([]);
Expand All @@ -34,6 +37,7 @@ const Cart = () => {
.then((response) => {
const shoppingCart = response.data.shoppingCart;
setCartItems(shoppingCart);
setCart(shoppingCart);

const initialQuantities = {};
shoppingCart.forEach((item) => {
Expand Down

0 comments on commit 2d3fd4b

Please sign in to comment.