useConsentManager

The useConsentManager hook provides access to the complete consent management API, allowing you to interact with and control the consent state throughout your application.

Usage useConsentManager

This example shows the hook being used to re-open the cookie banner once it has been closed. This could be used to re-open the banner after a certain amount of time has passed, or when a user wishes to update their consents for example.

Returns

The hook returns an object containing both state properties and methods for managing consent:

PropTypeDefault
consents
ConsentState
-
consentInfo
{ time: number; type: "necessary" | "all" | "custom"; }
-
showPopup
boolean
-
isLoadingConsentInfo
boolean
-
gdprTypes
AllConsentNames[]
-
isPrivacyDialogOpen
boolean
-
complianceSettings
Record<ComplianceRegion, ComplianceSettings>
-
callbacks
Callbacks
-
detectedCountry
string
-
locationInfo
LocationInfo
-
jurisdictionInfo
JurisdictionInfo
-
privacySettings
PrivacySettings
-
translationConfig
TranslationConfig
-
setTranslationConfig
(config: TranslationConfig) => void
-
includeNonDisplayedConsents
boolean
-
consentTypes
ConsentType[]
-
setConsent
(name: AllConsentNames, value: boolean) => void
-
setShowPopup
(show: boolean, force?: boolean | undefined) => void
-
setIsPrivacyDialogOpen
(isOpen: boolean) => void
-
saveConsents
(type: "necessary" | "all" | "custom") => void
-
resetConsents
() => void
-
setGdprTypes
(types: AllConsentNames[]) => void
-
setComplianceSetting
(region: ComplianceRegion, settings: Partial<ComplianceSettings>) => void
-
resetComplianceSettings
() => void
-
setCallback
(name: keyof Callbacks, callback: CallbackFunction | undefined) => void
-
setDetectedCountry
(country: string) => void
-
setLocationInfo
(location: LocationInfo | null) => void
-
setJurisdictionInfo
(jurisdiction: JurisdictionInfo | null) => void
-
fetchConsentBannerInfo
(url?: string | undefined) => Promise<ConsentBannerResponse | undefined>
-
getDisplayedConsents
() => ConsentType[]
-
hasConsented
() => boolean
-
clearAllData
() => void
-
updateConsentMode
() => void
-
setPrivacySettings
(settings: Partial<PrivacySettings>) => void
-
getEffectiveConsents
() => ConsentState
-
hasConsentFor
(consentType: AllConsentNames) => boolean
-
setIncludeNonDisplayedConsents
(include: boolean) => void
-

Notes

  • The hook must be used within a ConsentManagerProvider component
  • Throws an error if used outside of a ConsentManagerProvider
  • All methods are memoized and safe to use in effects or callbacks
  • Changes to consent state are automatically persisted
  • Supports TypeScript with full type safety

On this page

c15t.com