Sana Assistant (online)
Table of Contents

UseProductStockContext hook

const productContext = useProductStockContext();

This hook can be used in content element on product details page. Content elements can access stock information for product displayed on the page.

The useProductStockContext hook provides info about the product stock for content elements. This hook returns the object with data or null if it's not being used on the product details page, or stock information is not loaded yet.

The data contains following properties:

Property Type Description
inventory number The product inventory.
stockLevel 'inStock' | 'lowStock' | 'outOfStock' | 'preOrder' | null Stock level for current product or selected product variant.

Example:

  const stockContext = useProductStockContext();

  if (!stockContext)
    return null;

  const { 
    inventory,
    stockLevel,
  } = stockContext;
Hook Purpose
useProductContext Read product data, including the current variantId
useProductVariantContext Programmatically change the selected product variant
useProductPriceContext Read price for the currently selected variant