
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@kriegcc/react-cookie-consent
Advanced tools
A flexible, extensible library for managing user cookie consent in React applications.
Websites operating in the EU or serving EU users are required by EU data protection laws such as the GDPR to obtain valid consent before setting most cookies. Consent must be freely given, specific, informed, and provided through an affirmative action.
React Cookie Consent is a flexible, extensible library for managing user cookie consent in React applications. It aims to help to implement GDPR- and privacy-compliant consent flows.
The library provides classes, utility functions, contexts and hooks for consent management. The components can be used to build dialogs or modals for cookie consent and handle storing user preferences. The data structure is extensible and customizable to fit the applications needs.
A basic demo app is included to showcase implementation and demonstrate the library’s usage.
Have a look at the demo app for a full example of how to integrate the library and how to handle localization.
Define and Provide Cookie Data
validateCookiesJsonFile.Initialize the Cookie Consent Provider
CookieCategories map object from the JSON file via loadCookies.CookieCategories object to the CookieConsentProvider.Wrap Your App with the Provider
CookieConsentProvider at the root of your React application.Implement the Consent Flow
Store Data Accordingly
useConsentStorage hook.import { CookieConsentProvider, loadCookies, validateCookiesJsonFile } from "react-cookie-consent"
import cookiesJson from "./data/cookies.json"
const cookiesFile = validateCookiesJsonFile(cookiesJson) ? cookiesJson : { categories: [] }
const cookieCategories = loadCookies(cookiesFile)
<CookieConsentProvider initialCookieCategories={cookieCategories}>
<App />
</CookieConsentProvider>
For a complete example, see the demo app.
This library uses the following tools for development and build:
The project has some Node Dependencies which are required for the development and build process. They are listed in the package.json file.
Run the install command in the project's root folder to install the required dependencies.
pnpm i
The build command runs Vite, which uses the TypeScript compiler to compile the source files. Vite then optimizes and bundles the compiled code, placing the final output in the dist folder. The library is then ready for consumption or distribution.
pnpm build
The library includes a basic React demo app that showcases how to use the cookie consent library. The demo script command starts the Vite development server and hosts the app locally. By default, the browser will open automatically. The demo app is served at http://localhost:3000/.
pnpm demo
The test command runs the library’s unit tests.
pnpm test
ESLint and Prettier help maintain a high coding standard.
There are two script commands to ensure that the code adheres to the project's coding standards. Run the following commands to check for style violations:
ESLint:
pnpm lint
pnpm lint-fix
Prettier:
pnpm format
pnpm format-fix
Ideally, an IDE should automatically read the ESLint and Prettier configurations and provide direct feedback while writing code.
The project uses Semantic Versioning.
A changelog is available here: Changelog
See: License
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.