c15t
Version:
Headless JavaScript consent management platform for cookie banners, privacy preferences, consent storage, and script gating.
96 lines (69 loc) • 2.15 kB
Markdown
---
title: Checking Consent
description: Reference page for checking consent.
group: reference
---
## has(condition)
The `has()` method evaluates whether the current consent state satisfies a condition. It supports simple category checks and complex logical expressions.
### Simple Check
```tsx
const { has } = useConsentManager();
if (has('measurement')) {
// User has granted measurement consent
}
```
### AND Logic
All conditions must be true:
```tsx
has({ and: ['measurement', 'marketing'] })
// true only if BOTH measurement AND marketing are granted
```
### OR Logic
At least one condition must be true:
```tsx
has({ or: ['measurement', 'marketing'] })
// true if EITHER measurement OR marketing is granted
```
### NOT Logic
Negates a condition:
```tsx
has({ not: 'marketing' })
// true if marketing consent is NOT granted
```
### Nested Conditions
Combine operators for complex logic:
```tsx
has({
and: [
'necessary',
{ or: ['measurement', 'marketing'] },
{ not: 'functionality' },
],
})
// true if: necessary AND (measurement OR marketing) AND NOT functionality
```
### HasCondition Type
```ts
type HasCondition<CategoryType> =
| CategoryType // "measurement"
| { and: HasCondition[] | HasCondition } // { and: ["a", "b"] }
| { or: HasCondition[] | HasCondition } // { or: ["a", "b"] }
| { not: HasCondition } // { not: "a" }
```
## hasConsented()
Returns `true` if the user has made any consent choice (accepted, rejected, or customized). Returns `false` if no consent has been recorded yet.
```tsx
const { hasConsented } = useConsentManager();
if (hasConsented()) {
// User has previously made a consent choice
} else {
// First visit — no consent recorded
}
```
## getDisplayedConsents()
Returns the consent types that should be displayed in the UI (based on active `consentCategories` and each type's `display` property):
```tsx
const { getDisplayedConsents } = useConsentManager();
const visibleCategories = getDisplayedConsents();
// Returns ConsentType[] with name, description, defaultValue, etc.
```