Skip to main content

<GDPRConsentDialog>

<GDPRConsentDialog> is a stateful component used to manage the user's GDPR consent levels. Use this component to list the accepted levels and accept and/or reject additional levels.

If you need to access the stored consent levels, you can use the useGDPRConsent() hook.

Usage

<GDPRConsentDialog> can be rendered without passing in any props. The default settings will make the GDPR consent optional, as the user can dismiss the dialog without having to choose the consent levels.

import { GDPRConsentDialog } from "@slashid/react"

export default function Component() {
return (
<div>
<div>Page content</div>
<GDPRConsentDialog />
</div>
)
}

Demo with default options

If you want to force the user to choose consent levels, you can set the forceConsent prop to true. Interaction with your app is blocked until consent is given.

import { GDPRConsentDialog } from "@slashid/react"

export default function Component() {
return (
<div>
<div>Page content</div>
<GDPRConsentDialog forceConsent />
</div>
)
}

With necessary cookies

If some cookies are necessary for the basic functionality of your app, you can use the necessaryCookiesRequired prop to disable the removal of necessary cookies in the expanded dialog.

import { GDPRConsentDialog } from "@slashid/react"

export default function Component() {
return (
<div>
<div>Page content</div>
<GDPRConsentDialog necessaryCookiesRequired />
</div>
)
}

You can control which consent levels are stored when clicking on the "Accept all" and "Reject all" buttons by passing in the defaultAcceptAllLevels and defaultRejectAllLevels props.

import { GDPRConsentDialog } from "@slashid/react"

export default function Component() {
return (
<div>
<div>Page content</div>
<GDPRConsentDialog
defaultAcceptAllLevels={["necessary", "marketing"]}
defaultRejectAllLevels={["none", "necessary"]}
/>
</div>
)
}

Props

nametypedefaultdescription
className?stringOptional class name to be set on the dialog
triggerClassName?stringOptional class name to be set on the button that opens the dialog
necessaryCookiesRequired?booleanfalseDisable removal of necessary cookies in the expanded dialog
defaultAcceptAllLevels?GDPRConsentLevel[]All levels except noneControl what levels are accepted when clicking on Accept all
defaultRejectAllLevels?GDPRConsentLevel[][none]Control what levels are accepted when clicking on Reject all
forceConsent?booleanfalseDisable interactions outside the dialog until consent levels have been stored
forceOpen?booleanfalseOpen the dialog initially even if consent levels have been stored
container?HTMLElement | () => HTMLElementCustom portal container element that the dialog portals into
onSuccess?GDPRConsent[] => voidCalled when storing consent levels is successful
onError?Error => voidCalled when storing consent levels fails

Interfaces

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