Update src/app/cartContext.tsx

This commit is contained in:
2026-06-13 02:45:47 +00:00
parent 9073a8d6b0
commit 03ad91c7e3

View File

@@ -22,17 +22,16 @@ interface CartContextType {
const CartContext = createContext<CartContextType | undefined>(undefined);
export const CartProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [cartItems, setCartItems] = useState<CartItem[]>([]);
useEffect(() => {
// Load cart from localStorage on mount
const [cartItems, setCartItems] = useState<CartItem[]>(() => {
// 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