# VariantSelector The `VariantSelector` component helps you build a form for selecting available variants of a product. It is important for variant selection state to be maintained in the URL, so that the user can navigate to a product and return back to the same variant selection. It is also important that the variant selection state is shareable via URL. The `VariantSelector` component provides a render prop that renders for each product option. ### Example code ```jsx import {VariantSelector} from '@shopify/hydrogen'; import {Link} from '@remix-run/react'; const ProductForm = ({product}) => { return ( <VariantSelector handle={product.handle} options={product.options} variants={product.variants} > {({option}) => ( <> <div>{option.name}</div> <div> {option.values.map(({value, isAvailable, path, isActive}) => ( <Link to={path} prefetch="intent" className={ isActive ? 'active' : isAvailable ? '' : 'opacity-80' } > {value} </Link> ))} </div> </> )} </VariantSelector> ); }; ``` ```tsx import {VariantSelector} from '@shopify/hydrogen'; import type {Product} from '@shopify/hydrogen/storefront-api-types'; import {Link} from '@remix-run/react'; const ProductForm = ({product}: {product: Product}) => { return ( <VariantSelector handle={product.handle} options={product.options} variants={product.variants} > {({option}) => ( <> <div>{option.name}</div> <div> {option.values.map(({value, isAvailable, to, isActive}) => ( <Link to={to} prefetch="intent" className={ isActive ? 'active' : isAvailable ? '' : 'opacity-80' } > {value} </Link> ))} </div> </> )} </VariantSelector> ); }; ``` ## Props ### VariantSelectorProps ### handle The product handle for all of the variants ### options Product options from the [Storefront API](/docs/api/storefront/2023-07/objects/ProductOption). Make sure both `name` and `values` are apart of your query. ### variants Product variants from the [Storefront API](/docs/api/storefront/2023-07/objects/ProductVariant). You only need to pass this prop if you want to show product availability. If a product option combination is not found within `variants`, it is assumed to be available. Make sure to include `availableForSale` and `selectedOptions.name` and `selectedOptions.value`. ### productPath By default all products are under /products. Use this prop to provide a custom path. ### children ### VariantOption ### name ### value ### values ### VariantOptionValue ### value ### isAvailable ### to ### search ### isActive ## Related - [getSelectedProductOptions](/docs/api/hydrogen/2023-07/utilities/getselectedproductoptions)