1ConsentConsentDocs
Reference

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): ReactNode

Renders the synchronous CMP embed configuration, the inline React fast path, and application children without reading consent on the server.

Parameters and props

OptionDescriptionDefault
appId?: stringApplication 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?: stringCSP nonce for emitted scripts.
cmpSrc?: stringOverride the CMP embed URL derived from appId.
environment?: "local" | "develop" | "production"1Consent service environment.production
loadCmp?: booleanSet false when another integration loads the CMP embed.true
children?: ReactNodeApplication children.

Example

<OneConsentProvider appId="app_demo" fastPathVersions={fastPathVersions}>
  {children}
</OneConsentProvider>

OneConsent

function OneConsent(props: OneConsentProps): ReactNode

Serializes 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

OptionDescriptionDefault
service: RegisteredServiceNameService name, tag, or ID; mutually exclusive with category.
category: RegisteredCategoryNameCategory name or ID; mutually exclusive with service.
nonce?: stringCSP nonce for the inline resolve call.
once?: booleanPromote a matching global side-effect block at most once per page load.false
children?: ReactNodePlain 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): boolean

Returns 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

OptionDescriptionDefault
key: stringService or category name, tag, or ID.

Example

const analyticsAllowed = useConsent("Google Analytics");

Public types

OneConsentProps | OneConsentProviderProps | OneConsentEnvironment | OneConsentServiceMap | OneConsentCategoryMap | RegisteredServiceName | RegisteredCategoryName

Exported 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:

MemberTypePurpose
fastPathVersionsReadonly<Record<string, string>>Framework ID to structural build stamp map passed to OneConsentProvider.
OneConsentServiceName / OneConsentCategoryNamestring literal unionsNames and IDs aggregated across all published frameworks for the app.
serviceIds / categoryIdsRecord<generated name, string>Stable generated name-to-ID maps for customer application code.

On this page