Skip to content

Commit

Permalink
Merge pull request #909 from w3bdesign/801-react-18
Browse files Browse the repository at this point in the history
Framer motion & React 18
  • Loading branch information
w3bdesign authored Oct 2, 2022
2 parents 251d592 + 3a39781 commit 257ecd3
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 307 deletions.
8 changes: 6 additions & 2 deletions components/Cart/AddToCartButton.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const AddToCartButton = ({ product }) => {
const { data, refetch } = useQuery(GET_CART, {
notifyOnNetworkStatusChange: true,
onCompleted: () => {
refetch();
// Update cart in the localStorage.
const updatedCart = getFormattedCart(data);

Expand All @@ -54,12 +55,14 @@ const AddToCartButton = ({ product }) => {
input: productQueryInput,
},
onCompleted: () => {
console.log("Completed")
// Update the cart with new values in React context.
refetch();
// If error.
if (addToCartError) {
setRequestError(addToCartError.graphQLErrors[0].message);
}
// Update the cart with new values in React context.
refetch();

// Show View Cart Button
setShowViewCart(true);
setshowAddToCart(true);
Expand All @@ -74,6 +77,7 @@ const AddToCartButton = ({ product }) => {
const handleAddToCartClick = () => {
setRequestError(null);
addToCart();
refetch();
};

// Separate out conditions here for increased readability
Expand Down
2 changes: 2 additions & 0 deletions components/Cart/CartPage/CartItem.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const CartItem = ({
});
}
}

refetch();
};
return (
<tr className="bg-gray-100">
Expand Down
4 changes: 4 additions & 0 deletions components/Cart/CartPage/CartItemsContainer.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const CartItemsContainer = () => {
const { data, refetch } = useQuery(GET_CART, {
notifyOnNetworkStatusChange: true,
onCompleted: () => {
refetch();

// Update cart in the localStorage.
const updatedCart = getFormattedCart(data);
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
Expand Down Expand Up @@ -71,6 +73,8 @@ const CartItemsContainer = () => {
},
});
}

refetch();
};

useEffect(() => {
Expand Down
Loading

1 comment on commit 257ecd3

@vercel
Copy link

@vercel vercel bot commented on 257ecd3 Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.