Skip to content

Commit 368ac7a

Browse files
committed
Update CartProvider.tsx
1 parent a85c84c commit 368ac7a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/stores/CartProvider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ interface ICartContext {
5151
cart: RootObject | null | undefined;
5252
setCart: React.Dispatch<React.SetStateAction<TRootObjectNull>>;
5353
updateCart: (newCart: RootObject) => void;
54+
isLoading: boolean;
5455
}
5556

5657
const CartState: ICartContext = {
5758
cart: null,
5859
setCart: () => {},
5960
updateCart: () => {},
61+
isLoading: true,
6062
};
6163

6264
export const CartContext = createContext<ICartContext>(CartState);
@@ -66,6 +68,7 @@ export const CartContext = createContext<ICartContext>(CartState);
6668
*/
6769
export const CartProvider = ({ children }: ICartProviderProps) => {
6870
const [cart, setCart] = useState<RootObject | null>();
71+
const [isLoading, setIsLoading] = useState(true);
6972

7073
useEffect(() => {
7174
// Check if we are client-side before we access the localStorage
@@ -75,6 +78,7 @@ export const CartProvider = ({ children }: ICartProviderProps) => {
7578
const cartData: RootObject = JSON.parse(localCartData);
7679
setCart(cartData);
7780
}
81+
setIsLoading(false);
7882
}
7983
}, []);
8084

@@ -86,8 +90,8 @@ export const CartProvider = ({ children }: ICartProviderProps) => {
8690
};
8791

8892
const contextValue = useMemo(() => {
89-
return { cart, setCart, updateCart };
90-
}, [cart]);
93+
return { cart, setCart, updateCart, isLoading };
94+
}, [cart, isLoading]);
9195

9296
return (
9397
<CartContext.Provider value={contextValue}>

0 commit comments

Comments
 (0)