Product Hooks
useProduct()
useProduct()
When you are on a /products
template, any section, component, and or its children will have access to the page's data using the useProduct()
hook. That way, you do not have to drill this data down the props from the template.
Returns the full product
object from he currently navigated product route e.g /products/the-alfa
useProductByHandle()
useProductByHandle()
Returns a full product
object for any product from anywhere in the Storefront. In this example, we use the /products/the-alfa
inside a contact us page at /pages/contact
Arguments
This hook takes in an object with these properties
Key
Description
handle
A valid product handle.
fetchOnMount
Whether to fetch the requested product on the component mount. Defaults to true
. If you need to delay/control the fetch set this prop initially to false and then trigger it. e.g if using useInView
you could pass in the inView variable to it so that it fetches the product only when the component is visible.
useProductItemByHandle()
useProductItemByHandle()
Returns a product
object in its "item" form. An "item" is just a slimmed-down version of the full object, which may have more information than needed. This hook can be called from any route in the Storefront.
Arguments
This hook takes in an object with these properties
Key
Description
handle
A valid product handle.
fetchOnMount
Whether to fetch the requested product on the component mount. Defaults to true
. If you need to delay/control the fetch set this prop initially to false and then trigger it. e.g if using useInView
you could pass in the inView variable to it so that it fetches the product only when the component is visible.
useProductRecommendations()
useProductRecommendations()
options
handle
(optional) product handle. If no handle is provided the handle of the current product page will be used. e.g the handle returned by useProduct
limit
Limits the number of results.6 (default)
Or passing a custom product handle
useProductInventoryByHandle()
useProductInventoryByHandle()
In cases where live inventory data is critical, this hook helps you to easily fetch live inventory data
for any product route e.g fetching /products/charlie
inventory data within the /collections/all
route
options
handle
any valid product handle
fetchOnMount
wether live inventory should be auto-fetched on component mount true (default)
or false
useProductHandles()
useProductHandles()
Returns an array of all product handles in your Storefront.
Last updated