Sana Assistant (online)
Table of Contents

UseProductQuantityContext hook

const productQuantityContext = useProductQuantityContext();

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

The useProductQuantityContext hook provides info about the product quantity for content elements. This hook returns the object with data or null if it's not being used on the product details page.

The data contains following properties:

Property Type Description
quantity { value: number | string | null; isValid: boolean } The data about product quantity. value field displays the current quantity value. isValid indicates whether the current quantity value is valid.
updateQuantity (value: number | string | null) => void The callback to update product quantity.

Example:

  const productQuantityContext = useProductQuantityContext();

  if (!productQuantityContext)
    return null;

  const {
    quantity,
    updateQuantity,
  } = productPriceContext;