From 03ad91c7e30da5fc2e667956bf4a34095e7ea2f1 Mon Sep 17 00:00:00 2001 From: bender Date: Sat, 13 Jun 2026 02:45:47 +0000 Subject: [PATCH] Update src/app/cartContext.tsx --- src/app/cartContext.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/app/cartContext.tsx b/src/app/cartContext.tsx index 39b67af..d3e97df 100644 --- a/src/app/cartContext.tsx +++ b/src/app/cartContext.tsx @@ -22,17 +22,16 @@ interface CartContextType { const CartContext = createContext(undefined); export const CartProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { - const [cartItems, setCartItems] = useState([]); - - useEffect(() => { - // Load cart from localStorage on mount + const [cartItems, setCartItems] = useState(() => { + // Load cart from localStorage on initial render if (typeof window !== "undefined") { const storedCart = localStorage.getItem("shopwel_cart"); if (storedCart) { - setCartItems(JSON.parse(storedCart)); + return JSON.parse(storedCart); } } - }, []); + return []; + }); useEffect(() => { // Save cart to localStorage whenever it changes