useProductQuantity
This hook manages the product quantity on the product detail page. It reads and writes the quantity in page state with optional min/max constraints.
Import
import { useProductQuantity } from '@appmaker-xyz/shopify';
Basic Usage
const { productQuantity, setProductQuantity } = useProductQuantity({
minQuantity: 1,
maxQuantity: 10,
});
// Increase quantity
setProductQuantity(productQuantity + 1);
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
minQuantity | number | 1 | Minimum allowed quantity. |
maxQuantity | number | undefined | Maximum allowed quantity. No upper limit if not set. |
Return Value
| Property | Type | Description |
|---|---|---|
productQuantity | number | The current product quantity (defaults to 1). |
setProductQuantity | Function | Sets the quantity. Ignores values outside min/max range. Signature: (quantity: number) => void. |