From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Feb 2023 17:07:50 +0700 Subject: Refactor --- src/lib/cart/hooks/useCart.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/lib/cart/hooks/useCart.js (limited to 'src/lib/cart/hooks') diff --git a/src/lib/cart/hooks/useCart.js b/src/lib/cart/hooks/useCart.js new file mode 100644 index 00000000..44931b8a --- /dev/null +++ b/src/lib/cart/hooks/useCart.js @@ -0,0 +1,17 @@ +import { getCart } from "@/core/utils/cart" +import { useQuery } from "react-query" +import _ from "lodash" +import CartApi from "../api/CartApi" + +const useCart = () => { + const cart = getCart() + const variantIds = _.keys(cart).join(',') + const fetchCart = async () => CartApi({ variantIds }) + const { data, isLoading } = useQuery('cart', fetchCart) + + return { + cart: { data, isLoading } + } +} + +export default useCart \ No newline at end of file -- cgit v1.2.3 From d22df6bd30b8ed4bcfa938dcbbedc5fc376c2304 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 20 Feb 2023 10:49:35 +0700 Subject: cart refactor --- src/lib/cart/hooks/useCart.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/cart/hooks') diff --git a/src/lib/cart/hooks/useCart.js b/src/lib/cart/hooks/useCart.js index 44931b8a..9eb01e74 100644 --- a/src/lib/cart/hooks/useCart.js +++ b/src/lib/cart/hooks/useCart.js @@ -3,11 +3,11 @@ import { useQuery } from "react-query" import _ from "lodash" import CartApi from "../api/CartApi" -const useCart = () => { +const useCart = ({ enabled }) => { const cart = getCart() const variantIds = _.keys(cart).join(',') const fetchCart = async () => CartApi({ variantIds }) - const { data, isLoading } = useQuery('cart', fetchCart) + const { data, isLoading } = useQuery('cart', fetchCart, { enabled }) return { cart: { data, isLoading } -- cgit v1.2.3 From f66b12fd1d0b83af0d7230d7b1565fbe00afbe3c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 11:03:34 +0700 Subject: prettier --- src/lib/cart/hooks/useCart.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/lib/cart/hooks') diff --git a/src/lib/cart/hooks/useCart.js b/src/lib/cart/hooks/useCart.js index 9eb01e74..bc1ea7ea 100644 --- a/src/lib/cart/hooks/useCart.js +++ b/src/lib/cart/hooks/useCart.js @@ -1,7 +1,7 @@ -import { getCart } from "@/core/utils/cart" -import { useQuery } from "react-query" -import _ from "lodash" -import CartApi from "../api/CartApi" +import { getCart } from '@/core/utils/cart' +import { useQuery } from 'react-query' +import _ from 'lodash' +import CartApi from '../api/CartApi' const useCart = ({ enabled }) => { const cart = getCart() @@ -14,4 +14,4 @@ const useCart = ({ enabled }) => { } } -export default useCart \ No newline at end of file +export default useCart -- cgit v1.2.3