Next.js
Components
Component reference
c15t/next exports ConsentRoot and re-exports every component and hook from
c15t/react, so a Next.js app needs one import path. Every component except
ConsentTheme ships with 'use client'. You can still render them from a
Server Component, as long as every prop you pass is serializable.
| Component | Renders | Runs as | Reference |
|---|---|---|---|
ConsentRoot | The consent runtime, seeded with the state resolveConsent returned | Client Component | ConsentRoot |
ConsentBanner | The banner, when the visitor's policy asks for one | Client Component | ConsentBanner |
ConsentDialog | The preference center as a modal | Client Component | ConsentDialog |
ConsentWidget | The preference center inline in a page, for a privacy route | Client Component | ConsentWidget |
ConsentDialogLink | An unstyled button that opens the dialog, for your footer | Client Component | ConsentDialogLink |
ConsentDialogTrigger | A floating, draggable button that opens the dialog. ConsentDialogTriggerToolbar adds your own actions beside it | Client Component | ConsentDialogTrigger |
ConsentGate | Its children while a category is allowed, a placeholder otherwise | Client Component | ConsentGate |
ConsentTheme | A <style> element with your theme tokens | Server-safe | Customize |
DevTools from c15t/next/devtools | A development panel for consent state, scripts and events | Client Component | DevTools |
Render every component except ConsentTheme inside ConsentRoot, because
they read the runtime ConsentRoot creates. ConsentRoot already renders
ConsentProvider, so do not mount both.
Start with ConsentRoot, the banner and the dialog
Most apps start with four components. ConsentRoot holds the runtime,
ConsentBanner and ConsentDialog ask for a choice, and a
ConsentDialogLink lets visitors reopen their preferences. The quickstart
renders them in the root layout, a Server Component:
ConsentRoot reads c15t.config.ts, so the layout passes it only the
state from resolveConsent. The
Pages Router guide renders the same
components in pages/_app.tsx. Add ConsentWidget, ConsentDialogTrigger or
ConsentGate later, where a page needs them.
Server and Client Components
In the App Router, the 'use client' boundary decides what you can pass as a
prop:
ConsentRootreadsc15t.config.tsin the browser, so a Server Component passes it onlystate. ThestatefromresolveConsent, or its promise, is plain data and can cross. Put functions such as callbacks in the config, not in props from a Server Component.- Banner, dialog, widget, link, trigger and gate can render straight from
a Server Component page or layout under
ConsentRoot. Strings, numbers, booleans and JSX children cross the boundary. Function props, such as theonSelecthandler of aConsentDialogTriggerToolbaraction, need a'use client'file. ConsentThemehas no'use client'directive. Render it from a Server Component layout and the theme generator stays out of the browser bundle.DevToolsloads only in development. Import it withnext/dynamicandssr: false, as its page shows.
A component that reads consent state with a hook, such as useConsent, is
always a Client Component. See hooks.
IAB TCF components
c15t/next does not re-export the IAB TCF components. Import
IABProvider, IABConsentBanner and IABConsentDialog from c15t/react/iab,
render them inside ConsentRoot next to
ConsentBanner and ConsentDialog, and load c15t/next/styles.css and
c15t/next/iab/styles.css with styles: false. All three are Client
Components. The stock banner and dialog stay closed
under an IAB policy. See IAB TCF.
Other entry points
| Import | Exports | Use |
|---|---|---|
c15t/next/components/consent-dialog-link | ConsentDialogLink only | A module that needs the link without loading the rest of the adapter |
c15t/next/headless | Headless hooks | Your own banner and dialog markup. See headless |
c15t/next/server | resolveConsent and the other server helpers | Server Components and Route Handlers |
c15t/next/devtools | DevTools | Development only |
Check the components
Load the site in a private window under a policy that asks for a choice:
- The banner shows, and DevTools Network has no requests to your vendors' hosts.
- Click the footer's
ConsentDialogLink. The dialog opens with every optional category off. - Allow one category and save. Its vendor requests appear, and a
ConsentGatefor that category mounts its children. - Reload. The banner stays closed, and the link still reopens the dialog.
- View the page source. With the
awaited layout,
a first visit contains an element with
data-testid="consent-banner-root", and the page after your choice does not.