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:
name | type | default | description |
---|---|---|---|
isLoading | boolean | true | Dialog is ready to be used when it is done loading data |
consents | GDPRConsent[] | [] | Accepted consent levels with a timestamp |
updateGdprConsent | GDPRConsentLevel[] => 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:
GDPRConsentLevel
- a string representing a consent levelGDPRConsent
- an object with atimestamp
when the consentlevel
was accepted