Component

CookieConsent

GDPR-style cookie consent banner. Persists the user's choice to localStorage and fires a callback so the site can enable analytics/ads accordingly.

Usage β€” place in root layout

live editor β€” edit to update preview
"use client";
import { CookieConsent } from "@ann/ui";

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <CookieConsent
          onConsent={(value) => {
            if (value === "accepted") enableAnalytics();
          }}
        />
        {children}
      </body>
    </html>
  );
}

Read stored consent without rendering a component

live editor β€” edit to update preview
import { getStoredConsent } from "@ann/ui";

const consent = getStoredConsent(); // "accepted" | "declined" | null

Props

PropTypeDefaultDescription
onConsent(value: ConsentValue) => voidβ€”Called immediately when the user makes a choice, and on mount if a prior choice is stored.

ConsentValue type

type ConsentValue = "accepted" | "declined";

getStoredConsent()

Utility function (not a hook) that reads the persisted consent value from localStorage. Returns null when no choice has been made yet or when called server-side.