Use cases
Each recipe maps to a live Storybook story — run pnpm storybook and open
Skins/Minimalist/React or React/Headless/UseConsent.
Show a banner
Section titled “Show a banner”import { CookieConsentProvider } from "@vscookies/react";import { MinimalistBanner } from "@vscookies/skin-minimalist-react";
<CookieConsentProvider> <MinimalistBanner /></CookieConsentProvider>;The banner renders null after a decision, so you can mount it once and forget
it. → Storybook: Skins/Minimalist/React › Light.
Accept-only (hide reject)
Section titled “Accept-only (hide reject)”<MinimalistBanner showReject={false} />→ Storybook: Skins/Minimalist/React › Light (set showReject to false in Controls).
Custom copy and labels
Section titled “Custom copy and labels”<MinimalistBanner title="We value your privacy" description={<>We use cookies to run the site and measure traffic. <a href="/privacy">Privacy policy</a>.</>} acceptLabel="Sounds good" rejectLabel="Only essential"/>Every prop above has a live control in Storybook: Skins/Minimalist/React › Light (edit title, description, accept-label, and reject-label in the Controls panel).
Gate analytics behind consent
Section titled “Gate analytics behind consent”import { useEffect } from "react";import { useCookieConsent } from "@vscookies/react";
function Analytics() { const { hasConsented, state } = useCookieConsent(); useEffect(() => { if (hasConsented && state.analytics) initAnalytics(); }, [hasConsented, state.analytics]); return null;}→ Storybook: UseCases › Analytics Gating.
Category toggles (headless)
Section titled “Category toggles (headless)”Build a preferences panel from the hook:
function Categories() { const { state, set, acceptAll, rejectAll } = useCookieConsent(); return ( <div> {(["preferences", "analytics", "marketing"] as const).map((c) => ( <label key={c}> <input type="checkbox" checked={state[c]} onChange={(e) => set({ [c]: e.target.checked })} /> {c} </label> ))} <button onClick={acceptAll}>Accept all</button> <button onClick={rejectAll}>Reject all</button> </div> );}→ Storybook: UseCases › Category Toggles.
Several cookies per category
Section titled “Several cookies per category”When a category owns more than one cookie (for example two analytics cookies and
a marketing pixel), keep a typed registry and sync it with the store. The full
example — including deleting every cookie in a category when consent is revoked —
is in Core › Write multiple cookies per category.
consent.subscribe(() => syncCategoryCookies(consent.get()));syncCategoryCookies(consent.get());Re-consent after a policy change
Section titled “Re-consent after a policy change”Bump the consent version so existing records are ignored and the banner returns:
import { ConsentStore } from "@vscookies/core";
const store = new ConsentStore({ version: 2 });With the React provider (which uses version 1), call reset() when your policy
changes, or use core directly for a custom version. See
Build your own UI.
Dark mode
Section titled “Dark mode”Set the theme attribute on the root, or let the system preference decide:
<html data-vsc-theme="dark"><MinimalistBanner mode="dark" />→ Storybook: Skins/Minimalist/React › Dark, Skins/Edito/React › Ticket.
Use the Web Components anywhere
Section titled “Use the Web Components anywhere”With an import map in place (see Installing), import the vanilla runtime and a skin:
<script type="module"> import { defineAll } from "@vscookies/vanilla/define"; import "@vscookies/skin-edito-vanilla"; defineAll();</script>
<vscookies-edito mode="ticket" title="Cookies"></vscookies-edito>→ Storybook: Skins/Minimalist/WebComponent, Skins/Edito/WebComponent.
Both WebComponent stories expose the same Controls panel as their React
counterparts: text, boolean, mode radio and className. The
Skins/Playground story shows how many skins are active.