Skip to main content
Primer Checkout uses Web Components, which work natively in React. This guide covers React-specific patterns for both React 18 and React 19.
Using Next.js? See the SSR Guide first—you’ll need to load Primer on the client side only.

Quick start

Here’s a minimal working example for React 19:
For React 18, you need a ref to pass the options object. See React 18 Pattern below.

TypeScript setup

TypeScript doesn’t recognize custom web component tags by default. Add this declaration to your project:
Without this, you’ll see “Property ‘primer-checkout’ does not exist” errors.
For projects using multiple Primer components:

React 18 vs React 19

The key difference is how you pass object properties to web components.
React 19 passes objects directly as properties:

Handling payment events

Listen for payment events to handle success and failure:

Stable object references

Define options objects outside your component or use useMemo. This avoids unnecessary work on every render.
The SDK uses deep comparison, so inline objects won’t break functionality. But stable references are still recommended to avoid comparison overhead on every render.

Common patterns

Show loading while checkout initializes

Fetch client token from server

Checkout in a modal

Custom hook (optional)

This pattern is not required. It’s provided for teams who prefer encapsulating logic in reusable hooks. The examples above work perfectly without it.
Encapsulate checkout logic in a reusable hook:

Complete example

A production-ready checkout component with all the patterns combined:
Usage:

Quick reference

See also

SSR Guide

Next.js, Nuxt, and SvelteKit patterns

SDK Options

All configuration options

Events Guide

Complete event reference

Styling

Customize the appearance