Skip to content

Commit cfe7a13

Browse files
committed
Refetch
1 parent bc03a92 commit cfe7a13

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

components/Cart/AddToCartButton.component.jsx

Lines changed: 5 additions & 3 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,7 +77,6 @@ const AddToCartButton = ({ product }) => {
7477
const handleAddToCartClick = () => {
7578
setRequestError(null);
7679
addToCart();
77-
// Update the cart with new values in React context.
7880
refetch();
7981
};
8082

0 commit comments

Comments
 (0)