Skip to content

npm package Open source

@tryonit/react: Virtual Try-On Components for React

React components and hooks that add a "Try it on" button to any product page, with full theming and a headless API for Next.js, Remix and Vite.

Overview

@tryonit/react is the package most stores use from TryOnIt, the open-source virtual try-on SDK I built. One line, <TryOnButton asset="/tryon/aviator.json" />, adds a button that opens an accessible try-on dialog with the live camera, a product switcher, shade swatches, an intensity slider, a before and after comparison and a capture preview with download and share. It wraps the @tryonit/web engine and needs no provider for the simple case.

I designed it so a store never has to fight the UI. Theme tokens become CSS custom properties with no CSS-in-JS runtime. Every slot accepts a class name, and the stylesheet uses low-specificity selectors so yours win without !important. An unstyled mode removes the visuals but keeps layout and accessibility, slots replace whole sub-components, and headless hooks such as useTryOn and useTryOnState let a team build the interface from scratch. Every string, icon and image is replaceable, including right-to-left layouts.

Per-frame tracking data never passes through React state, so re-renders stay rare, and useTryOnState only re-renders when the slice you select changes. Components are SSR safe and ship with "use client", so Next.js App Router pages import them directly. The package is about 8 KB min+gzip, and its dialog has a focus trap, Escape to close, focus return and screen reader announcements.

Key features

  • Drop-in <TryOnButton> that preloads models on hover or when visible
  • Accessible dialog: focus trap, Escape, focus return and live status
  • Theme tokens, class names per slot, unstyled mode and replaceable slots
  • Headless hooks: useTryOn, useTryOnState, useCamera, useAsset, useCapture
  • SSR safe for the Next.js App Router, Pages Router and Remix
  • Replaceable labels and icons, dark mode and right-to-left layouts

Articles about this project

Have an app in mind?

Tell me what you're building. I reply to every serious enquiry within two working days.