summaryrefslogtreecommitdiff
path: root/src/lib/cart/hooks
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-17 17:07:50 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-17 17:07:50 +0700
commitf99e0aba70efad0deb907d8e27f09fc9f527c8a4 (patch)
treef0ac96e4e736a1d385e32553f0e641ee27e11fd3 /src/lib/cart/hooks
parent90e1edab9b6a8ccc09a49fed3addbec2cbc4e4c3 (diff)
Refactor
Diffstat (limited to 'src/lib/cart/hooks')
-rw-r--r--src/lib/cart/hooks/useCart.js17
1 files changed, 17 insertions, 0 deletions
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