LGPD-compliant cookie consent management for React — this package is the aggregator that re-exports the MUI components for backwards compatibility. If you need a smaller bundle or headless API, prefer @react-lgpd-consent/core or @react-lgpd-consent/mui.
react-lgpd-consent is the compatibility aggregator for the v0.5.x monorepo. It re-exports the ready-made MUI components and keeps the API compatible with previous releases. If you want to optimize your bundle, import only @react-lgpd-consent/core (headless) or @react-lgpd-consent/mui/ui (MUI components only).
Key features:
Install the package and peer dependencies:
npm install react-lgpd-consent
# ensure peer deps are present in the host app
npm install react react-dom @mui/material @emotion/react @emotion/styled js-cookie --save-peer
This package re-exports @react-lgpd-consent/mui for compatibility. Import only what you need to reduce bundle size.
Minimal example (API compatible with v0.4.x):
import React from 'react'
import { ConsentProvider, useConsent } from 'react-lgpd-consent'
export default function App() {
return (
<ConsentProvider categories={{ enabledCategories: ['analytics', 'marketing'] }}>
<YourApp />
</ConsentProvider>
)
}
function YourApp() {
const { preferences, setPreference } = useConsent()
return (
<div>
<button onClick={() => setPreference('marketing', true)}>Accept Marketing</button>
</div>
)
}
Load a script only if the user granted the related category:
import { ConsentScriptLoader, COMMON_INTEGRATIONS } from 'react-lgpd-consent'
function Analytics() {
return (
<ConsentScriptLoader
integrations={[
COMMON_INTEGRATIONS.googleAnalytics({ measurementId: 'GA_MEASUREMENT_ID' }),
]}
/>
)
}
<ConsentProvider
onConsentInit={(state) => console.log('Initialized:', state)}
onConsentChange={(current, prev) => console.log('Changed:', current)}
onAuditLog={(entry) => fetch('/api/audit', {
method: 'POST',
body: JSON.stringify(entry)
})}
>
import { createAnpdCategoriesConfig } from 'react-lgpd-consent'
const categories = createAnpdCategoriesConfig({
include: ['analytics', 'marketing']
})
import { createConsentAuditEntry } from 'react-lgpd-consent'
const audit = createConsentAuditEntry(state, {
action: 'update',
consentVersion: '1'
})
📖 Full documentation: API.md | TROUBLESHOOTING.md
| Package | Description |
|---|---|
@react-lgpd-consent/core |
Headless logic (no UI) — build your own UI |
@react-lgpd-consent/mui |
Ready-to-use MUI components |
react-lgpd-consent |
Aggregator (re-exports MUI) — backward compatibility |
Follow DEVELOPMENT.md in the repo. Suggested flow:
git checkout -b feat/my-featuregit commit -m "feat: description"Before opening PR run the local pipeline:
npm run type-check
npm test
npm run lint
npm run build
npm run docs:generate
MIT © Luciano Edipo — see the LICENSE file.
If you want the Portuguese README, see README.md in the same package.