React SDK Reference
React 19+ integration for inert consent-gated markup, synchronous returning-visitor acceleration, and reactive consent reads.
Developer preview: @1consent/react is still workspace-private. The API below is the source-backed contract; public package installation starts only after the provenance-backed release.
OneConsentProvider
function OneConsentProvider(props: OneConsentProviderProps): ReactNodeRenders the synchronous CMP embed configuration, the inline React fast path, and application children without reading consent on the server.
Parameters and props
| Option | Description | Default |
|---|---|---|
appId?: string | Application short ID; falls back to NEXT_PUBLIC_1CONSENT_APP_ID. | — |
fastPathVersions?: Readonly<Record<string, string>> | Framework ID to structural build stamp map generated by 1c typegen. | — |
nonce?: string | CSP nonce for emitted scripts. | — |
cmpSrc?: string | Override the CMP embed URL derived from appId. | — |
environment?: "local" | "develop" | "production" | 1Consent service environment. | production |
loadCmp?: boolean | Set false when another integration loads the CMP embed. | true |
children?: ReactNode | Application children. | — |
Example
<OneConsentProvider appId="app_demo" fastPathVersions={fastPathVersions}>
{children}
</OneConsentProvider>OneConsent
function OneConsent(props: OneConsentProps): ReactNodeSerializes plain HTML children into an inert template and promotes them when the selected service or category has consent. Exactly one gating key is required.
Parameters and props
| Option | Description | Default |
|---|---|---|
service: RegisteredServiceName | Service name, tag, or ID; mutually exclusive with category. | — |
category: RegisteredCategoryName | Category name or ID; mutually exclusive with service. | — |
nonce?: string | CSP nonce for the inline resolve call. | — |
once?: boolean | Promote a matching global side-effect block at most once per page load. | false |
children?: ReactNode | Plain HTML elements to serialize; React components are unsupported. | — |
Example
<OneConsent service="Google Analytics" once>
<script src="https://example.com/analytics.js" />
</OneConsent>useConsent
function useConsent(key: string): booleanReturns the current consent decision for a service or category key and re-renders when consent changes. Returns false until consent is known.
Parameters and props
| Option | Description | Default |
|---|---|---|
key: string | Service or category name, tag, or ID. | — |
Example
const analyticsAllowed = useConsent("Google Analytics");Public types
OneConsentProps | OneConsentProviderProps | OneConsentEnvironment | OneConsentServiceMap | OneConsentCategoryMap | RegisteredServiceName | RegisteredCategoryNameExported prop and declaration-merging types. Generated service/category modules augment the empty maps to make registered names autocomplete and type-check.
Generated module from 1c typegen
Commit the generated module or run 1c typegen --app <shortId> --check in CI. It augments the public React maps and exports:
| Member | Type | Purpose |
|---|---|---|
fastPathVersions | Readonly<Record<string, string>> | Framework ID to structural build stamp map passed to OneConsentProvider. |
OneConsentServiceName / OneConsentCategoryName | string literal unions | Names and IDs aggregated across all published frameworks for the app. |
serviceIds / categoryIds | Record<generated name, string> | Stable generated name-to-ID maps for customer application code. |