Skip to main content

Next.js Consent API

Hooks

Read only the state you need

Every hook reads the runtime from the ConsentRoot set up in your App Router or Pages Router guide, so call them from a Client Component rendered inside that root and import them from c15t/next.

components/optional-feature.tsx
'use client';

import { useConsent } from 'c15t/next';

export function OptionalFeature() {
	const allowed = useConsent('marketing');
	return allowed ? <div>Optional marketing content</div> : null;
}

Call hooks inside the consent provider. useConsent reads effective permission, which can be true under an opt-out policy without a recorded grant.

NeedHook
One category's current permissionuseConsent(category)
All current permissionsuseConsents()
Recorded per-category choicesuseExplicitChoice()
Whether one declared vendor may runuseVendorAllowed(id)
Whether a prompt is requiredusePromptRequirement()
Active policy and resolutionusePolicyRule(), usePolicyResolution()
Save an explicit choiceuseSaveConsents()
Open or close a consent surfaceuseSetActiveUI()
Acknowledge a noticeuseDismissNotice()

Save from a visitor action

Place this Client Component inside your existing consent boundary.

components/reject-button.tsx
'use client';

import { useSaveConsents } from 'c15t/next';

export function RejectButton() {
	const save = useSaveConsents();
	return (
		<button type="button" onClick={() => void save('none')}>
			Reject optional
		</button>
	);
}

This is an isolated action example, not a complete policy-aware banner. Use the stock UI or headless surface actions for a complete prompt. Do not call save on mount to persist a state derived from permissions.

Use focused hooks for feature gates. For a complete custom prompt or preference center, use useHeadlessConsentUI() for surface actions and useConsentDraft() for staged choices, inside one ConsentDraftProvider so the save commits the same draft. v3 has no useConsentManager(); the use-consent-manager-to-hooks codemod rewrites most of its calls to hooks. Read how consent works before treating a callback as evidence of a choice.