Integrate Katla cookie consent into any React application.
The @katla.app/sdk/react entry point provides React components and hooks for managing cookies and consent. Use it with Vite, Create React App, or any client-side React setup.
For Next.js projects, use the Next.js guide instead — it provides a streamlined setup for the App Router.
Headless hook that combines cookie data, consent state, and window.KatlaConsent actions into a single API. Use it to build fully custom consent UIs without boilerplate.
Copy
import { useConsentManager } from '@katla.app/sdk/react';function MyConsentUI() { const { ready, // true once window.KatlaConsent is available hasDecision, // true after the visitor has accepted/rejected open, // preferences panel visibility setOpen, selected, // currently toggled-on categories availableCategories, // categories with cookies (excludes functional/unknown) toggleCategory, acceptAll, // calls KatlaConsent.acceptAll() and closes the panel rejectAll, // calls KatlaConsent.rejectAll() and closes the panel saveSelection, // calls KatlaConsent.acceptCategories() and closes the panel cookies, // { data, loading, error } } = useConsentManager(); if (!ready) return null; return ( <div> {!hasDecision && ( <div> <p>We use cookies.</p> <button onClick={acceptAll}>Accept all</button> <button onClick={rejectAll}>Reject all</button> <button onClick={() => setOpen(true)}>Customize</button> </div> )} {open && ( <div> {availableCategories.map((cat) => ( <label key={cat}> <input type="checkbox" checked={selected.includes(cat)} onChange={() => toggleCategory(cat)} /> {cat} </label> ))} <button onClick={saveSelection}>Save</button> </div> )} </div> );}
Return field
Type
Description
ready
boolean
true once window.KatlaConsent is available
hasDecision
boolean
true after the visitor has made a consent choice
open
boolean
Whether the preferences panel is visible
setOpen
(open: boolean) => void
Toggle the preferences panel
selected
ManageableCategory[]
Currently selected categories
availableCategories
ManageableCategory[]
Categories that have cookies (excludes functional and unknown)
toggleCategory
(cat: ManageableCategory) => void
Toggle a category on/off
acceptAll
() => void
Accept all categories and close the panel
rejectAll
() => void
Reject non-essential categories and close the panel
saveSelection
() => void
Save selected categories and close the panel
cookies
{ data, loading, error }
Cookie data from useKatlaCookies()
The ManageableCategory type ('personalization' | 'analytics' | 'marketing' | 'security') is also exported for type-safe category handling.
A ready-to-use consent banner with accept, reject, and per-category customization. The component is unstyled — it renders semantic HTML with stable katla-* class names you can target with your own CSS.
The fastest way to add a consent banner is with the <CookieBanner> component — it handles all the consent logic out of the box. For full control, use the useConsentManager hook or call window.KatlaConsent methods directly.
window.KatlaConsent is provided by the guard script. It becomes available after KatlaGuard mounts and the script loads. The ConsentBridge component handles polling for it and relaying events to React.
If your framework supports server-side rendering (Remix, Astro, etc.), fetch cookies on the server and pass them to the provider to avoid a client-side network request:
Copy
// Server-side (e.g. Remix loader)import { createKatlaClient } from '@katla.app/sdk';const client = createKatlaClient({ siteId: 'your-site-id' });const cookies = await client.getCookies();
Copy
// Client componentimport { KatlaProvider } from '@katla.app/sdk/react';function App({ cookies }) { return ( <KatlaProvider siteId="your-site-id" initialCookies={cookies}> {/* useKatlaCookies() returns data immediately — no fetch */} </KatlaProvider> );}
The guard script and consent bridge still run client-side. Only the cookie data fetch is moved to the server.