Skip to content

Commit 570271d

Browse files
committed
Update AddToCart.component.tsx
1 parent 368ac7a commit 570271d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/components/Product/AddToCart.component.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const AddToCart = ({
9696
variationId,
9797
fullWidth = false,
9898
}: IProductRootObject) => {
99-
const { setCart, cart } = useContext(CartContext);
99+
const { setCart, isLoading: isCartLoading } = useContext(CartContext);
100100
const [requestError, setRequestError] = useState<boolean>(false);
101101

102102
const productId = product?.databaseId ? product?.databaseId : variationId;
@@ -141,10 +141,6 @@ const AddToCart = ({
141141
});
142142

143143
const handleAddToCart = () => {
144-
if (!cart) {
145-
console.log('Cart is not yet initialized. Please wait.');
146-
return;
147-
}
148144
addToCart();
149145
// Refetch cart after 2 seconds
150146
setTimeout(() => {
@@ -156,10 +152,10 @@ const AddToCart = ({
156152
<>
157153
<Button
158154
handleButtonClick={() => handleAddToCart()}
159-
buttonDisabled={addToCartLoading || requestError || !cart}
155+
buttonDisabled={addToCartLoading || requestError || isCartLoading}
160156
fullWidth={fullWidth}
161157
>
162-
{!cart ? 'Loading...' : 'KJØP'}
158+
{isCartLoading ? 'Loading...' : 'KJØP'}
163159
</Button>
164160
</>
165161
);

0 commit comments

Comments
 (0)