PactDOCS

INTEGRATE / REACT

React and headless

Use idiomatic context and gates, or suppress Pact-owned UI and render every pixel yourself.
01

Wrap the application

pnpm add @pact/react @pact/runtime
App.tsx
tsx
import { PactGate, PactProvider } from '@pact/react'

export function App() {
  return (
    <PactProvider siteKey="site_live_your_key" src="/pact.js" apiBase="/v1">
      <PactGate purpose="analytics">
        <Analytics />
      </PactGate>
      <YourApp />
    </PactProvider>
  )
}
02

Read decisions with hooks

AnalyticsGate.tsx
tsx
import { usePactPurpose } from '@pact/react'

export function AnalyticsGate() {
  const allowed = usePactPurpose('analytics')
  return allowed ? <Analytics /> : null
}
03

Own the complete interface

Headless mode renders no Pact consent surface. State, GPC restrictions, evidence, and actions remain active.

PrivacyExperience.tsx
tsx
function Root({ children }) {
  return <PactProvider siteKey="site_live_your_key" mode="headless">
    <PrivacyExperience />
    {children}
  </PactProvider>
}

function PrivacyExperience() {
  const { decided, gpc, purposes, accept, reject, save } = usePact()
  // Your components. Your CSS. Your motion.
}
Open the exercised headless implementation
REFERENCERead the React API