File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff 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
5657const CartState : ICartContext = {
5758 cart : null ,
5859 setCart : ( ) => { } ,
5960 updateCart : ( ) => { } ,
61+ isLoading : true ,
6062} ;
6163
6264export const CartContext = createContext < ICartContext > ( CartState ) ;
@@ -66,6 +68,7 @@ export const CartContext = createContext<ICartContext>(CartState);
6668 */
6769export 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 } >
You can’t perform that action at this time.
0 commit comments