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.

If there is no authenticated user, the consent levels will be stored in local storage. Otherwise, the consent levels will be stored using the SlashID API.

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: