Skip to content

Commit

Permalink
Define refetch() before we use it
Browse files Browse the repository at this point in the history
  • Loading branch information
w3bdesign committed Mar 2, 2021
1 parent 112469c commit d257577
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions components/Cart/CartPage/CartItemsContainer.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ const CartItemsContainer = () => {
const [cart, setCart] = useContext(AppContext);
const [requestError, setRequestError] = useState(null);

const { data, refetch } = useQuery(GET_CART, {
notifyOnNetworkStatusChange: true,
onCompleted: () => {
// Update cart in the localStorage.
const updatedCart = getFormattedCart(data);
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
// Update cart data in React Context.
setCart(updatedCart);
},
onError: (error) => {
setRequestError(error);
},
});

// Update Cart Mutation.
const [updateCart, { loading: updateCartProcessing }] = useMutation(
UPDATE_CART,
Expand Down Expand Up @@ -58,19 +72,6 @@ const CartItemsContainer = () => {
}
};

const { data, refetch } = useQuery(GET_CART, {
notifyOnNetworkStatusChange: true,
onCompleted: () => {
// Update cart in the localStorage.
const updatedCart = getFormattedCart(data);
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
// Update cart data in React Context.
setCart(updatedCart);
},
onError: (error) => {
setRequestError(error);
},
});
return (
<>
<section className="py-8 bg-white">
Expand Down

0 comments on commit d257577

Please sign in to comment.