@@ -17,6 +17,20 @@ const CartItemsContainer = () => {
17
17
const [ cart , setCart ] = useContext ( AppContext ) ;
18
18
const [ requestError , setRequestError ] = useState ( null ) ;
19
19
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
+
20
34
// Update Cart Mutation.
21
35
const [ updateCart , { loading : updateCartProcessing } ] = useMutation (
22
36
UPDATE_CART ,
@@ -58,19 +72,6 @@ const CartItemsContainer = () => {
58
72
}
59
73
} ;
60
74
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
- } ) ;
74
75
return (
75
76
< >
76
77
< section className = "py-8 bg-white" >
0 commit comments