Skip to main content
Hosted Checkout provides a global React store through useCheckout(). No context provider is required.

Installation

Choose the correct authentication mode before initializing:

Checkout-only React app

Use managed mode when the React app does not use the Storefront SDK. Checkout creates and owns the anonymous/logged-in session. Initialize once in a root component and clean up on unmount:
src/checkout-bootstrap.tsx
Mount <CheckoutBootstrap /> once near the application root.

React app with Storefront SDK

When @commercengine/storefront is present, managed mode would create a second independent session. Use authMode: "provided" and synchronize tokens in both directions. Follow React SDK integration for the complete provided-mode pattern: storefront config with onTokensUpdated, session bootstrap, and checkout init and teardown.
Do not use the checkout-only managed-mode setup above in a React app that also imports @commercengine/storefront. The two sessions diverge and the cart silently splits in two.
For Next.js and TanStack Start, use their dedicated SDK integration pages because the Storefront SDK callback is configured on the framework wrapper rather than inside a SPA session object.

Use the hook

src/components/cart-button.tsx
src/components/add-to-cart-button.tsx
Pass null for products without variants. For products with variants, do not enable the button until the UI resolves a purchasable variantId.

Open checkout directly

For a product-specific Quick Buy session, configure quickBuy at initialization. See Configuration.

Hook API

Error and lifecycle handling

Use initialization callbacks for app-level behaviour:
Do not enable cart actions until isReady is true. Do not initialize checkout in every route component.

Next.js

Use a root Client Component that first calls storefront.bootstrap(), then initializes checkout in provided mode. Follow Next.js SDK integration; do not use the checkout-only managed-mode example in a Next.js storefront that imports @commercengine/storefront.

Production checklist

React starter implementations

Review both Vite React and React meta-framework starters for complete lifecycle, catalog, and deployment patterns.