Files
breakpilot-compliance/consent-sdk/src/react/hooks.ts
T
Sharang Parnerkar 4ed39d2616 refactor(consent-sdk): split ConsentManager + framework adapters under 500 LOC
Phase 4: extract config defaults, Google Consent Mode helper, and framework
adapter internals into sibling files so every source file is under the
hard cap. Public API surface preserved; all 135 tests green, tsup build +
tsc typecheck clean.

- core/ConsentManager 525 -> 467 LOC (extract config + google helpers)
- react/index 511 LOC -> 199 LOC barrel + components/hooks/context
- vue/index 511 LOC -> 32 LOC barrel + components/composables/context/plugin
- angular/index 509 LOC -> 45 LOC barrel + interface/service/module/templates

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 22:25:44 +02:00

44 lines
1.1 KiB
TypeScript

/**
* React hooks for the consent SDK.
*
* Phase 4: extracted from index.tsx to keep the main file under 500 LOC.
*/
import { useContext } from 'react';
import type { ConsentCategory } from '../types';
import type { ConsentManager } from '../core/ConsentManager';
import { ConsentContext, type ConsentContextValue } from './context';
/**
* useConsent - Consent-Hook.
* Overloads: call without args for the full context; pass a category to also get `allowed`.
*/
export function useConsent(): ConsentContextValue;
export function useConsent(
category: ConsentCategory
): ConsentContextValue & { allowed: boolean };
export function useConsent(category?: ConsentCategory) {
const context = useContext(ConsentContext);
if (!context) {
throw new Error('useConsent must be used within a ConsentProvider');
}
if (category) {
return {
...context,
allowed: context.hasConsent(category),
};
}
return context;
}
/**
* useConsentManager - Direkter Zugriff auf ConsentManager.
*/
export function useConsentManager(): ConsentManager | null {
const context = useContext(ConsentContext);
return context?.manager ?? null;
}