Skip to content

ConsentStore

Defined in: store.ts:51

Framework-agnostic consent state machine.

The store hydrates from the cookie on first read, keeps decisions in memory, and broadcasts changes to subscribers. Adapters (@tickboxhq/react, @tickboxhq/vue) bind to it via their idiomatic reactivity primitive.

Constructors

new ConsentStore()

new ConsentStore(config, options): ConsentStore

Defined in: store.ts:57

Parameters

ParameterType
configConsentConfig
optionsStoreOptions

Returns

ConsentStore

Methods

close()

close(): void

Defined in: store.ts:158

Returns

void


deny()

deny(id): void

Defined in: store.ts:128

Parameters

ParameterType
idstring

Returns

void


denyAll()

denyAll(): void

Defined in: store.ts:139

Returns

void


dismissNotice()

dismissNotice(): void

Defined in: store.ts:170

Close the notice card without persisting. Most sites won’t need this — save() already closes the notice as part of acknowledgement. Use this when you want to hide the notice without recording a decision (e.g. routing away from a page where it’s inappropriate to show it).

Returns

void


getState()

getState(): ConsentState

Defined in: store.ts:113

Returns

ConsentState


grant()

grant(id): void

Defined in: store.ts:124

Parameters

ParameterType
idstring

Returns

void


grantAll()

grantAll(): void

Defined in: store.ts:133

Returns

void


hydrate()

hydrate(): void

Defined in: store.ts:75

Read the stored cookie and update state. Safe to call on the server (no-op when document is unavailable). Call from a mount effect.

Returns

void


hydrateFromHeader()

hydrateFromHeader(cookieHeader): void

Defined in: store.ts:84

Hydrate from a raw Cookie header — for server-side rendering. Pass the value of the request’s cookie header (or undefined if absent).

Parameters

ParameterType
cookieHeaderundefined | string

Returns

void


isRequired()

isRequired(id): boolean

Defined in: store.ts:189

Parameters

ParameterType
idstring

Returns

boolean


open()

open(): void

Defined in: store.ts:152

Returns

void


reset()

reset(): void

Defined in: store.ts:177

Wipe stored consent and reopen the banner / notice as appropriate.

Returns

void


save()

save(): void

Defined in: store.ts:146

Persist the current decisions and close both the banner and the notice.

Returns

void


subscribe()

subscribe(fn): () => void

Defined in: store.ts:117

Parameters

ParameterType
fnListener

Returns

Function

Returns

void