Skip to content

Commit 257ecd3

Browse files
authored
Merge pull request #909 from w3bdesign/801-react-18
Framer motion & React 18
2 parents 251d592 + 3a39781 commit 257ecd3

File tree

5 files changed

+338
-307
lines changed

5 files changed

+338
-307
lines changed

components/Cart/AddToCartButton.component.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const AddToCartButton = ({ product }) => {
3434
const { data, refetch } = useQuery(GET_CART, {
3535
notifyOnNetworkStatusChange: true,
3636
onCompleted: () => {
37+
refetch();
3738
// Update cart in the localStorage.
3839
const updatedCart = getFormattedCart(data);
3940

@@ -54,12 +55,14 @@ const AddToCartButton = ({ product }) => {
5455
input: productQueryInput,
5556
},
5657
onCompleted: () => {
58+
console.log("Completed")
59+
// Update the cart with new values in React context.
60+
refetch();
5761
// If error.
5862
if (addToCartError) {
5963
setRequestError(addToCartError.graphQLErrors[0].message);
6064
}
61-
// Update the cart with new values in React context.
62-
refetch();
65+
6366
// Show View Cart Button
6467
setShowViewCart(true);
6568
setshowAddToCart(true);
@@ -74,6 +77,7 @@ const AddToCartButton = ({ product }) => {
7477
const handleAddToCartClick = () => {
7578
setRequestError(null);
7679
addToCart();
80+
refetch();
7781
};
7882

7983
// Separate out conditions here for increased readability

components/Cart/CartPage/CartItem.component.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const CartItem = ({
4949
});
5050
}
5151
}
52+
53+
refetch();
5254
};
5355
return (
5456
<tr className="bg-gray-100">

components/Cart/CartPage/CartItemsContainer.component.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const CartItemsContainer = () => {
2020
const { data, refetch } = useQuery(GET_CART, {
2121
notifyOnNetworkStatusChange: true,
2222
onCompleted: () => {
23+
refetch();
24+
2325
// Update cart in the localStorage.
2426
const updatedCart = getFormattedCart(data);
2527
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
@@ -71,6 +73,8 @@ const CartItemsContainer = () => {
7173
},
7274
});
7375
}
76+
77+
refetch();
7478
};
7579

7680
useEffect(() => {

0 commit comments

Comments
 (0)