ConsentProvider
Shares a single useConsent decision via React context so every consent-aware component reads the same stored choice. Mount once near the app root; accepts every useConsent option including version and a pluggable storage adapter.
Design intent
Cookie consent needs one source of truth: the banner writes a decision, gated scripts read it, and a preferences dialog edits it. ConsentProvider holds that decision in context so components never duplicate storage keys or drift apart; standalone useConsent remains available for provider-free setups.
npx @slipstream-ui/cli@latest add consent-providerWe use cookies
Everything inside the provider — the probe, the banner, gated scripts — shares this one decision.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Application tree that consumes the consent context. |
| storageKey | string | 'slipstream-consent' | Storage key for the persisted decision. |
| purposes | readonly string[] | ['analytics'] | Consent purposes persisted as booleans. |
| maxAgeMs | number | — | How long a stored decision stays valid before re-prompting (default 180 days). |
| version | string | — | Policy version — a decision written under another version is treated as undecided. |
| storage | ConsentStorage | — | Pluggable persistence adapter; defaults to window.localStorage. |
Anti-patterns
validate_usage is the MCP tool that rejects these mistakes: the same list agents see over MCP and in the canonical markdown.
Don't nest providers with different keys
Components read the nearest provider. Two providers with different storageKeys or purposes produce inconsistent consent state; use one provider per storage key.
tsx// Avoid<ConsentProvider storageKey="a"><ConsentProvider storageKey="b">...Don't call useConsentContext outside the provider
The hook throws a descriptive error outside ConsentProvider. For provider-free usage, call the standalone useConsent hook instead.
tsx// Avoidconst consent = useConsentContext(); // no provider// Preferconst consent = useConsent({ storageKey: 'app-consent' });
Accessibility
- Renders no UI of its own — accessibility lives in ConsentBanner and ConsentPreferencesDialog.
- useConsentContext throws a descriptive error outside the provider; standalone useConsent remains available.
Composition
Compose with ConsentBanner: Presentational banner wired to the provider's decision via useConsentContext or manual useConsent
const consent = useConsentContext(); <ConsentBanner onAccept={() => consent.setAll(true)} ... />
Compose with ConsentPreferencesDialog: Edits per-category preferences through consent.set
<ConsentPreferencesDialog open={open} onOpenChange={setOpen} categories={categories} />
Compose with ConsentScript: Injects scripts only while the matching category is granted
<ConsentScript category="analytics" src="https://example.com/a.js" />
Related components: ConsentBanner, ConsentPreferencesDialog, ConsentScript
Dependencies
What the registry installs alongside this component. Package imports already include these.
npm packages
- class-variance-authority
- clsx
- tailwind-merge
Browser support
| Browser | Tested versions |
|---|---|
| Chrome | 111+ (Mar 2023) |
| Edge | 111+ (Mar 2023) |
| Firefox | 121+ (Dec 2023) |
| Safari | 17.2+: macOS & iOS (Dec 2023) |
Slipstream components rely only on CSS custom properties, Flexbox/Grid, and ARIA, the everyday baseline of the last two years of evergreen releases. Anything newer is progressive enhancement: unsupported browsers keep full functionality with static behavior instead of animations.