Skip to main content

useGDPRConsent()

useGDPRConsent() is a stateful hook providing access to the current user's GDPR consent levels. Use this hook to list the accepted levels and accept and/or reject additional levels.

Consent levels will be stored using the current user, if the user is authenticated or the Anonymous users API is enabled. Otherwise, the consent levels will be stored using local storage.

Usage

import { useGDPRConsent } from "@slashid/react"

function Component() {
const { consents, isLoading } = useGDPRConsent()

if (isLoading) {
return <div>Loading consent levels...</div>
}

// state is "ready" so consent levels are now up to date
}

API

This hook does not require any props to be passed in. It returns an object with the following properties:

nametypedefaultdescription
isLoadingbooleantrueDialog is ready to be used when it is done loading data
consentsGDPRConsent[][]Accepted consent levels with a timestamp
updateGdprConsentGDPRConsentLevel[] => Promise<GDPRConsent[]>Add or remove the recorded consent levels
deleteGdprConsent() => Promise<void>Delete the recorded consent levels

Interfaces

The following interfaces are being used in the components's API: