cookieconsent vs react-cookie-consent
GDPR Cookie Consent Solutions for Web Applications
cookieconsentreact-cookie-consent

GDPR Cookie Consent Solutions for Web Applications

cookieconsent and react-cookie-consent are both npm packages designed to help websites comply with cookie consent regulations like GDPR and CCPA by displaying customizable banners that let users accept or reject non-essential cookies. cookieconsent is a framework-agnostic vanilla JavaScript library that operates independently of any UI framework, while react-cookie-consent is a purpose-built React component that integrates directly into React applications using JSX and React's state management.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
cookieconsent03,533-937 years agoMIT
react-cookie-consent063672.6 kB12 months agoMIT

cookieconsent vs react-cookie-consent: Technical Comparison for GDPR Compliance

Both cookieconsent and react-cookie-consent help websites comply with privacy regulations like GDPR by displaying consent banners to users. However, they differ significantly in architecture, integration style, and customization capabilities. Let’s break down how they work in practice.

🧱 Core Architecture: Vanilla JS vs React Component

cookieconsent is a vanilla JavaScript library that works independently of any frontend framework. It injects a DOM element and manages its own state and styling.

// cookieconsent: Initialize with plain JS
import cookieconsent from 'cookieconsent';

cookieconsent.initialise({
  palette: {
    popup: { background: '#000' },
    button: { background: '#f1d600' }
  },
  theme: 'classic',
  content: {
    message: 'This site uses cookies.',
    dismiss: 'Got it!'
  }
});

react-cookie-consent is a React component that integrates directly into your JSX tree. It leverages React’s state and lifecycle, making it feel native in React apps.

// react-cookie-consent: Use as a React component
import CookieConsent from 'react-cookie-consent';

function App() {
  return (
    <>
      <main>Your app content</main>
      <CookieConsent
        location="bottom"
        buttonText="Accept"
        cookieName="myAwesomeCookieConsent"
        style={{ background: "#2B373B" }}
        buttonStyle={{ color: "#4e503b", fontSize: "13px" }}
      >
        This website uses cookies!
      </CookieConsent>
    </>
  );
}

⚙️ Configuration Style: Imperative vs Declarative

cookieconsent uses an imperative configuration object passed to initialise(). Options are nested under categories like palette, theme, and content.

// cookieconsent: Nested config structure
cookieconsent.initialise({
  type: 'opt-in',
  position: 'bottom-left',
  revokable: true,
  onInitialise: function(status) {
    // handle initial state
  },
  onStatusChange: function(status, chosenBefore) {
    // handle user interaction
  }
});

react-cookie-consent uses JSX props, which aligns with React’s declarative model. Each visual or behavioral option is a top-level prop.

// react-cookie-consent: Flat props interface
<CookieConsent
  disableStyles={false}
  enableDeclineButton={true}
  flipButtons={true}
  onAccept={() => console.log('Accepted')}
  onDecline={() => console.log('Declined')}
  declineButtonText="Reject"
/>

🎨 Styling Approach: Built-in Themes vs CSS-in-JS

cookieconsent ships with predefined themes (classic, edgeless) and expects you to override colors via the palette config. You can also load optional CSS files.

// cookieconsent: Theme-based styling
cookieconsent.initialise({
  theme: 'edgeless',
  palette: {
    popup: { background: '#34495e', text: '#ffffff' },
    button: { background: '#3498db' }
  }
});

react-cookie-consent uses inline styles (CSS-in-JS) via props like style, buttonStyle, and contentStyle. This gives fine-grained control without external CSS.

// react-cookie-consent: Inline style props
<CookieConsent
  style={{ background: "#333", padding: "15px" }}
  buttonStyle={{ background: "#007bff", borderRadius: "4px" }}
  contentStyle={{ flex: "1", marginRight: "10px" }}
/>

🔄 State Management and Lifecycle Hooks

cookieconsent provides callback hooks like onInitialise, onStatusChange, and onPopupOpen to respond to user actions. It manages its own internal state.

// cookieconsent: Callback-driven events
cookieconsent.initialise({
  onStatusChange: function(status, chosenBefore) {
    if (this.hasConsented()) {
      // enable analytics
    }
  }
});

react-cookie-consent exposes event handler props such as onAccept and onDecline. Since it’s a React component, you can tie its visibility to your app’s state if needed.

// react-cookie-consent: Event handler props
<CookieConsent
  onAccept={() => {
    // enable tracking scripts
  }}
  onDecline={() => {
    // disable non-essential cookies
  }}
/>

📦 Integration Complexity in React Apps

In a React application, cookieconsent requires extra care:

  • Must be initialized in useEffect to avoid SSR issues.
  • Needs manual cleanup to prevent memory leaks.
  • Doesn’t re-render when props change unless you re-initialize.
// Using vanilla cookieconsent in React (not ideal)
import { useEffect } from 'react';
import cookieconsent from 'cookieconsent';

function CookieBanner() {
  useEffect(() => {
    cookieconsent.initialise({ /* config */ });
    return () => {
      // No official destroy method — potential leak
    };
  }, []);

  return null; // Renders nothing; DOM injected externally
}

react-cookie-consent avoids these pitfalls:

  • Naturally fits into React’s render cycle.
  • Props updates trigger re-renders automatically.
  • No external DOM manipulation or cleanup needed.
// React-native integration
function App() {
  const [showBanner, setShowBanner] = useState(true);

  return (
    <>
      {showBanner && (
        <CookieConsent onAccept={() => setShowBanner(false)} />
      )}
    </>
  );
}

🌐 Browser Support and Dependencies

cookieconsent has no dependencies and supports older browsers (including IE9+). It’s designed to be lightweight and standalone.

react-cookie-consent requires React 16.8+ (for hooks) and assumes a modern JavaScript environment. It does not support legacy browsers out of the box.

🛑 Maintenance Status

As of the latest npm and GitHub data:

  • cookieconsent is actively maintained, with recent releases addressing bugs and compatibility.
  • react-cookie-consent is also actively maintained, with regular updates and community contributions.

Neither package is deprecated, so both are viable for new projects — but your choice should depend on your tech stack.

✅ When to Use Which?

  • If you’re building a non-React site (vanilla JS, Vue, Svelte, etc.), cookieconsent is the clear choice.
  • If you’re in a React codebase, react-cookie-consent offers better integration, fewer side effects, and a more predictable development experience.

Avoid mixing cookieconsent into React apps unless you have a strong reason — the impedance mismatch leads to harder-to-maintain code.

How to Choose: cookieconsent vs react-cookie-consent

  • cookieconsent:

    Choose cookieconsent if you're working outside the React ecosystem — such as with vanilla JavaScript, Vue, Angular, or server-rendered pages without a component framework. It’s lightweight, dependency-free, and gives you full control over initialization and theming through a configuration object. However, integrating it into React requires careful lifecycle management and may lead to anti-patterns like external DOM manipulation.

  • react-cookie-consent:

    Choose react-cookie-consent if you're building a React application and want a seamless, idiomatic solution that respects React’s rendering model. It uses props for configuration, supports inline styling, and handles user interactions through standard event handlers. This avoids the need for manual DOM injection or cleanup, making your code more maintainable and less prone to hydration or memory issues.

README for cookieconsent

Build Status

What is Cookie Consent?

Cookie Consent is a lightweight JavaScript plugin for alerting users about the use of cookies on your website.

It is designed to help you comply with the hideous EU Cookie Law and not make you want to kill yourself in the process. So we made it fast, free, and relatively painless.

Warning: Phishing attempt

Several users have been emailed with a phishing attempt trying to get them to move the URL they link to from the cdnjs link that is provided on our website as cdnjs is "going away". This is not associated with us and will most likely result in malicious sideloaded code on your website.

Version 3.0

Version 3.0 is a complete rewrite from version 2. The most substantial new features are:

  • the ability to GeoLocate and only show the addon to people in the relevant countries
  • callback hooks for showing/accepting/revoking the banner
  • support for different types of compliance, giving you the flexibility to obey even the strictest cookie laws
  • easy no-fuss themes and customisable styles

Installation

The easiest way to get up and running is to use our wizard.

You can also install this project through npm:

npm install cookieconsent

Or through Bower:

bower install cookieconsent

Or via a jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js"></script>

Documentation

See our full documentation.

Contributing

Feel free to improve the plugin and send us a pull request.

The easiest way to develop is to host the files with a local webserver. e.g.

python -m SimpleHTTPServer

We use Gulp to compile the SCSS and minify the JavaScript. You can run a build with:

gulp build

License

Code released under the MIT licence.

Credits

Cookie Consent v3

  • Alex Morley-Finch (@alexmorleyfinch) - JavaScript
  • Piiu Pilt - JavaScript
  • Oliver Emberton (@oliveremberton) - a couple of lines of CSS, maybe

Cookie Consent v2

  • David Ball (@drball) - CSS / themes
  • Adam Hutchinson (@adjohu) - JavaScript