Skip to content

Commit b4ceee7

Browse files
authored
Merge pull request #383 from w3bdesign/develop
Define refetch() before we use it
2 parents 0f472db + d257577 commit b4ceee7

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

components/Cart/CartPage/CartItemsContainer.component.jsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ const CartItemsContainer = () => {
1717
const [cart, setCart] = useContext(AppContext);
1818
const [requestError, setRequestError] = useState(null);
1919

20+
const { data, refetch } = useQuery(GET_CART, {
21+
notifyOnNetworkStatusChange: true,
22+
onCompleted: () => {
23+
// Update cart in the localStorage.
24+
const updatedCart = getFormattedCart(data);
25+
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
26+
// Update cart data in React Context.
27+
setCart(updatedCart);
28+
},
29+
onError: (error) => {
30+
setRequestError(error);
31+
},
32+
});
33+
2034
// Update Cart Mutation.
2135
const [updateCart, { loading: updateCartProcessing }] = useMutation(
2236
UPDATE_CART,
@@ -58,19 +72,6 @@ const CartItemsContainer = () => {
5872
}
5973
};
6074

61-
const { data, refetch } = useQuery(GET_CART, {
62-
notifyOnNetworkStatusChange: true,
63-
onCompleted: () => {
64-
// Update cart in the localStorage.
65-
const updatedCart = getFormattedCart(data);
66-
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
67-
// Update cart data in React Context.
68-
setCart(updatedCart);
69-
},
70-
onError: (error) => {
71-
setRequestError(error);
72-
},
73-
});
7475
return (
7576
<>
7677
<section className="py-8 bg-white">

0 commit comments

Comments
 (0)