A lightweight & customizable cookie banner for your React App
npm install react-cookienotice> A lightweight & customizable cookie banner for your React App






- 🍃 No dependency, full self-made package (Bundlephobia)
- 📱 Mobile first & responsive
- ⚙️ Customizable with several props
- ⏱️ Very fast setup (less than 1 minute)
- 🧪 Tested with unit & functional tests
- 🌙 Dark mode based on system settings
- 🌎 Translated in Deutsch, English, Español, Français, Italiano, 한국인, Occitan & 中文 (create issue or submit pull request for more languages)
``bash`
npm i --save react-cookienotice
`bash`
yarn add react-cookienotice
> If you're using a SSR framework like Next.js, see Troubleshooting section.
`tsx
import React from 'react'
import { CookieNotice } from 'react-cookienotice'
import 'react-cookienotice/style'
const Example = () =>
export default Example
`
All props are optionals.
If you want a "Read More" link, you must set all of the following props:
- readMoreLabelreadMoreLink
- readMoreInNewTab
-
| Key | Type | Description | Default value |
| ----------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| acceptAllButtonLabel | string | The label for the accept all cookies button. | Accept all (translated in browser language) |Function
| onAcceptAllButtonClick | | A callback function to be called when the accept all cookies button is clicked. | - |string
| declineAllButtonLabel | | The label for the decline all cookies button. | Decline all (translated in browser language) |Function
| onDeclineAllButtonClick | | A callback function to be called when the decline all cookies button is clicked. | - |string
| customizeButtonLabel | | The label for the customize cookies button. | Customize (translated in browser language) |string
| customizeTitleLabel | | The title for the customize view. | Customize (translated in browser language) |ServiceObject[]
| services | | List of services to be customized. | - |string
| acceptButtonLabel | | The label for the accept button. | Accept (translated in browser language) |Function
| onAcceptButtonClick | | A callback function to be called when the accept cookies button is clicked. The first param returns the checked services. | - |string
| backButtonLabel | | The label for the back button. | Back (translated in browser language) |string
| alwaysActiveLabel | | The label for the always active services. | Always active (translated in browser language) |string
| customizeAcceptAllButtonLabel | | The label for the accept all button in the customize view. | Accept all (translated in browser language) |number
| customizeAcceptAllTimeout | | The timeout for the accept all button in the customize view. | 1000 |string
| titleLabel | | The title for the cookie banner. | Cookie consent (translated in browser language) |string
| descriptionLabel | | The description for the cookie banner. | By clicking Accept, you consent to our website's use of cookies to provide you with the most relevant experience by remembering your cookie preferences. (translated in browser language) |string
| readMoreLabel | | The label for the read more link. | - |string
| readMoreLink | | The link for the read more label. | - |boolean
| readMoreInNewTab | | Whether the read more link should open in a new tab. | - |PlacementOptions
| placement | | The placement of the cookie banner. | { vertical: 'bottom', horizontal: 'left' } |CookieOptions
| cookieOptions | | Cookie options. | { name: 'hide-notice', value: 'true', expires: 30, secure: false, httpOnly: false, sameSite: 'lax' } |
For SSR you need to import dynamically the module with next/dynamic using { ssr: false }. This prevents the component from being included on the server, and dynamically loads it on the client-side only.
Create a new file which include the CookieNotice component :
`tsx
import { CookieNotice } from 'react-cookienotice'
import 'react-cookienotice/style'
export default function CookieBanner() {
return
}
`
then you can import it wherever the component is used :
`tsx
import dynamic from 'next/dynamic'
const CookieBanner = dynamic(() => import('./cookie-banner'), { ssr: false })
export default function Home() {
return
}
``
MIT © xavierbriole
Built with Vite ⚡