UNPKG

@konkonam/nuxt-shopify

Version:

Easily integrate shopify with nuxt 3 and 4 🚀

18 lines (17 loc) • 665 B
import { useAsyncData } from "#app"; import { useStorefront } from "./storefront.js"; export function useAsyncStorefront(...args) { if (args.length < 2 || args.length > 4) { throw new Error("[shopify] [useAsyncStorefront] Invalid number of arguments"); } const hasKey = args.length === 4 || args.length === 3 && typeof args[1] === "string"; if (!hasKey) { args.unshift(""); } const [key, operation, options, asyncOptions = {}] = args; const handler = () => useStorefront().request(operation, options).then((r) => r.data); if (hasKey) { return useAsyncData(key, handler, asyncOptions); } return useAsyncData(handler, asyncOptions); }