Skip to content

Commit 885aff9

Browse files
committed
Fix "'refetch' was used before it was defined."
1 parent 83a97dc commit 885aff9

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

components/Checkout/CheckoutForm.component.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ const CheckoutForm = () => {
2121
const [requestError, setRequestError] = useState(null);
2222
const [orderCompleted, setorderCompleted] = useState(false);
2323

24+
// Get Cart Data.
25+
const { data, refetch } = useQuery(GET_CART, {
26+
notifyOnNetworkStatusChange: true,
27+
onCompleted: () => {
28+
// Update cart in the localStorage.
29+
const updatedCart = getFormattedCart(data);
30+
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
31+
// Update cart data in React Context.
32+
setCart(updatedCart);
33+
},
34+
});
35+
2436
// Checkout GraphQL mutation
2537
const [checkout, { loading: checkoutLoading }] = useMutation(
2638
CHECKOUT_MUTATION,
@@ -39,17 +51,7 @@ const CheckoutForm = () => {
3951
}
4052
);
4153

42-
// Get Cart Data.
43-
const { data, refetch } = useQuery(GET_CART, {
44-
notifyOnNetworkStatusChange: true,
45-
onCompleted: () => {
46-
// Update cart in the localStorage.
47-
const updatedCart = getFormattedCart(data);
48-
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
49-
// Update cart data in React Context.
50-
setCart(updatedCart);
51-
},
52-
});
54+
5355

5456
useEffect(() => {
5557
if (null !== orderData) {

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-woocommerce",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"description": "NextJS WooCommerce webshop",
55
"main": "index.js",
66
"scripts": {
@@ -24,7 +24,7 @@
2424
"react": "^17.0.1",
2525
"react-dom": "^17.0.1",
2626
"react-hook-form": "^6.15.4",
27-
"react-instantsearch-dom": "^6.10.0",
27+
"react-instantsearch-dom": "^6.10.1",
2828
"react-spring": "^8.0.27",
2929
"styled-components": "^5.2.1",
3030
"uuid": "^8.3.2"

0 commit comments

Comments
 (0)