Skip to main content

useProductVariations

This hook is usd to get the product variations in product list.

note

This hook is used only in the ProductList component to render the variation options for a product. For ProductDetail component, use the useProductOptions hook.

propstypedescription
isSingleVariationboolean
isMultiOptionsboolean
optionsobject
selectedOptionsobject
selectedVariantobject
setOptionsfunction
variantobject
salePricenumber
regularPricenumber
regularPriceWithCurrencystring
salePriceWithCurrencystring
imageUrlstring
salePercentagenumber
onSaleboolean
isVariantAvailableboolean

Usage:

import { useProductVariations } from '@appmaker-xyz/shopify';

export default function ProductListItem(props) {
const {
options,
setOptions,
variant,
selectedVariant,
salePrice,
regularPrice,
imageUrl,
selectedOptions,
salePercentage,
onSale,
regularPriceWithCurrency,
salePriceWithCurrency,
isMultiOptions,
isVariantAvailable,
} = useProductVariations(props);

return (
<View>
<Text>{variant.title}</Text>
</View>
);

setoptions function is used to set the selected options.

<View>
{isMultiOptions ? (
<View>
{options?.map?.((opt) =>
Object.values(opt?.values).map((item, index) => (
<TouchableOpacity
key={index}
onPress={() => {
setOptions({ [opt.label]: item.id });
}}>
</TouchableOpacity>
)),
)}
</View>
) : null}
</View>