Skip to main content
The useProduct hook is the all-in-one product-detail hook: it fetches the product and runs the whole variant-selection engine — option pills state, the disabled-option matrix, a clamped quantity stepper, and add-to-cart with a double-submit guard. No app has to re-implement the option matrix anymore.

Usage

Hook API

Back-compat: useProduct('handle') (string input) still works, and data remains an alias of the raw node for screens written against the legacy shape. useVariantSelector(product) and useCartQuantity({ minQty, maxQty }) are exported separately for screens that fetch product data another way.

How the variant engine works

  • Default selection is the first variant’s answers — the same default the Shopify storefront picks.
  • Availability matrix: an option value is available if some in-stock variant offering it agrees with every other currently-selected option. Values the product declares but no variant carries never become reachable.
  • Resolution: selectedVariant is the exact match; an existing-but-sold-out combination still resolves (so you can say “out of stock” rather than pretending it doesn’t exist), while a never-created combination resolves null and isAvailable goes false.
  • Impossible combinations are shown, not hidden: strike-through / dim the unavailable pills like the Shopify PDP does.

Query Fields

The detail query returns:
  • Basic fields: id, title, handle, description, descriptionHtml
  • availableForSale, tags, productType, vendor
  • priceRange — min/max variant prices
  • images(first: 10) — all images with url, altText, width, height
  • variants(first: 20) — with id, title, availableForSale, price, compareAtPrice, sku, quantityAvailable, selectedOptions, image
  • options — product options with name and values
  • seo — { title, description }
  • metafields(first: 20) — only when requested via metafields

Metafields in one round trip

Pass explicit identifiers when your store scopes accessible metafields; omit them to pull whatever the default namespace exposes. Either way it is fetched with the product — no second request.

Lower-level engine pieces

The pure matcher (normalizeProductForSelection, buildOptionGroups, resolveSelectedVariant, …) is exported too, so web/storybook code can reuse the same resolution logic outside React.