Skip to content

useTryYourSize()

Hook@tryyoursize/react

The TryYourSize client, or null until it has loaded.

function useTryYourSize(): TryYourSizeClient | null

TryYourSizeClient | null: The client, or null until it has loaded. Throws outside a provider.

function SizeBadge({ sku }: { sku: string }) {
const tys = useTryYourSize();
const [size, setSize] = useState<string | null>(null);
useEffect(() => {
tys?.recommendation(sku).then((r) => setSize(r.status === "ready" ? r.size : null));
}, [tys, sku]);
return size ? <span>Your size: {size}</span> : null;
}

Was this page helpful?