--- name: vtex-io-storefront-react description: "Apply when building VTEX IO storefront components under react/ for Store Framework experiences. Covers storefront component structure, css-handles, storefront context hooks, browser-safe data fetching, and how components should behave when used as theme blocks. Use for custom storefront UI, product widgets, banners, forms, or reviewing shopper-facing React code in VTEX IO apps." --- # Storefront React Components ## When this skill applies Use this skill when building shopper-facing React components under the `react` builder for storefront experiences. - Creating product or category UI widgets - Building custom banners, forms, and shopper-facing layout pieces - Using storefront hooks or context providers - Styling components with css-handles Do not use this skill for: - admin pages - block registration and render-runtime contracts - service runtime or backend route design - GraphQL schema design ## Decision rules - Treat storefront components as browser-facing UI and keep them safe for shopper contexts. - Prefer keeping storefront components presentational and props-driven, and move complex data fetching or business logic to hooks or container components. - Use `vtex.css-handles` instead of hardcoded global class names. - Prefer receiving data through props or documented storefront hooks and contexts such as `useProduct`, `useRuntime`, or `useOrderForm` instead of calling VTEX APIs directly from the browser or using app keys in storefront code. - Keep components resilient to loading, empty, and unavailable product or search context. - For shopper-facing copy, use message IDs and helpers from the messages infrastructure, as described in `vtex-io-messages-and-i18n`, instead of string literals. - Treat storefront components as part of the storefront accessibility surface: use semantic HTML elements such as `button` or `a` instead of clickable `div`s, and ensure important content has appropriate labels or alternative text. - When accessing browser globals such as `window` or `document`, guard against server-side execution, for example by using `useEffect` or checking `typeof window !== 'undefined'`. ## Hard constraints ### Constraint: Storefront styling must use css-handles Storefront components MUST expose styling through `css-handles`, not arbitrary hardcoded class names. **Why this matters** css-handles are the customization contract for storefront components. Hardcoded or hidden class names make themes harder to extend safely. **Detection** If a storefront component uses arbitrary global class names without css-handles, STOP and expose styling through handles first. **Correct** ```tsx const CSS_HANDLES = ['container', 'title'] as const ``` **Wrong** ```tsx return