From 368ac7aae96bb86090f377213439a64d65807622 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Wed, 23 Oct 2024 06:16:43 +0200 Subject: [PATCH] Update CartProvider.tsx --- src/stores/CartProvider.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stores/CartProvider.tsx b/src/stores/CartProvider.tsx index 0b041579e..c6bcbc690 100644 --- a/src/stores/CartProvider.tsx +++ b/src/stores/CartProvider.tsx @@ -51,12 +51,14 @@ interface ICartContext { cart: RootObject | null | undefined; setCart: React.Dispatch>; updateCart: (newCart: RootObject) => void; + isLoading: boolean; } const CartState: ICartContext = { cart: null, setCart: () => {}, updateCart: () => {}, + isLoading: true, }; export const CartContext = createContext(CartState); @@ -66,6 +68,7 @@ export const CartContext = createContext(CartState); */ export const CartProvider = ({ children }: ICartProviderProps) => { const [cart, setCart] = useState(); + const [isLoading, setIsLoading] = useState(true); useEffect(() => { // Check if we are client-side before we access the localStorage @@ -75,6 +78,7 @@ export const CartProvider = ({ children }: ICartProviderProps) => { const cartData: RootObject = JSON.parse(localCartData); setCart(cartData); } + setIsLoading(false); } }, []); @@ -86,8 +90,8 @@ export const CartProvider = ({ children }: ICartProviderProps) => { }; const contextValue = useMemo(() => { - return { cart, setCart, updateCart }; - }, [cart]); + return { cart, setCart, updateCart, isLoading }; + }, [cart, isLoading]); return (