summaryrefslogtreecommitdiff
path: root/src/lib/cart/hooks
diff options
context:
space:
mode:
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..bc1ea7ea
--- /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 = ({ enabled }) => {
+ const cart = getCart()
+ const variantIds = _.keys(cart).join(',')
+ const fetchCart = async () => CartApi({ variantIds })
+ const { data, isLoading } = useQuery('cart', fetchCart, { enabled })
+
+ return {
+ cart: { data, isLoading }
+ }
+}
+
+export default useCart