npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tinyconsent-react

v1.0.1

Published

React component for TinyConsent cookie consent banners. One component, full GDPR/CCPA compliance.

Readme

tinyconsent-react

npm version License: MIT TypeScript

The easiest cookie banner React component. One component for GDPR/CCPA-style cookie consent banners.

A lightweight React component for adding TinyConsent cookie consent banners to your React, Next.js, Gatsby, or any React-based application.

Why TinyConsent React?

  • ⚛️ React-native - Proper React component, not a script hack
  • 🚀 One component - Just <TinyConsentScript id="..." />
  • 📦 Tiny - Under 1KB, loads the actual banner async
  • Cookie consent handling - Loads your TinyConsent banner and lets you wire consent into your tracking scripts
  • 🔧 Designed for Google Consent Mode v2 - Works with GA4-style implementations
  • 🎨 Customizable - Configure via dashboard, no code changes
  • 📱 SSR Ready - Works with Next.js, Remix, Gatsby

Get your script ID: tinyconsent.com/cookie-banner-generator

Installation

npm install tinyconsent-react
yarn add tinyconsent-react
pnpm add tinyconsent-react

Quick Start

import { TinyConsentScript } from 'tinyconsent-react';

function App() {
  return (
    <>
      <TinyConsentScript id="your-script-id" />
      <div>My App Content</div>
    </>
  );
}

That's it! Your cookie consent banner will appear automatically.

What It Renders

The <TinyConsentScript /> component renders:

<script src="https://scripts.tinyconsent.com/api/scripts/your-script-id" async></script>

No internal logic, no bloat - just the script tag that loads your cookie banner.

API Reference

<TinyConsentScript />

React component that renders the TinyConsent script tag.

<TinyConsentScript
  id="your-script-id"        // Required: Your TinyConsent script ID
  async={true}               // Optional: Load async (default: true)
  defer={false}              // Optional: Defer execution (default: false)
  nonce="abc123"             // Optional: CSP nonce
  onLoad={() => {}}          // Optional: Called when loaded
  onError={(err) => {}}      // Optional: Called on error
/>

useTinyConsent(scriptId)

React hook for programmatic loading.

import { useTinyConsent } from 'tinyconsent-react';

function App() {
  const { isLoading, isLoaded, error } = useTinyConsent('your-script-id');
  
  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error loading banner</div>;
  
  return <div>My App</div>;
}

getTinyConsentScriptUrl(scriptId)

Get the full script URL.

import { getTinyConsentScriptUrl } from 'tinyconsent-react';

const url = getTinyConsentScriptUrl('your-script-id');
// 'https://scripts.tinyconsent.com/api/scripts/your-script-id'

Framework Examples

Next.js (App Router)

// app/layout.tsx
import { TinyConsentScript } from 'tinyconsent-react';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <TinyConsentScript id="your-script-id" />
      </head>
      <body>{children}</body>
    </html>
  );
}

Next.js (Pages Router)

// pages/_app.tsx
import { TinyConsentScript } from 'tinyconsent-react';

export default function App({ Component, pageProps }) {
  return (
    <>
      <TinyConsentScript id="your-script-id" />
      <Component {...pageProps} />
    </>
  );
}

Gatsby

// gatsby-browser.js
import React from 'react';
import { TinyConsentScript } from 'tinyconsent-react';

export const wrapRootElement = ({ element }) => (
  <>
    <TinyConsentScript id="your-script-id" />
    {element}
  </>
);

Create React App / Vite

// src/App.tsx
import { TinyConsentScript } from 'tinyconsent-react';

function App() {
  return (
    <>
      <TinyConsentScript id="your-script-id" />
      <div className="App">
        {/* Your app content */}
      </div>
    </>
  );
}

Remix

// app/root.tsx
import { TinyConsentScript } from 'tinyconsent-react';

export default function App() {
  return (
    <html lang="en">
      <head>
        <Meta />
        <Links />
        <TinyConsentScript id="your-script-id" />
      </head>
      <body>
        <Outlet />
        <Scripts />
      </body>
    </html>
  );
}

What is a Cookie Banner?

A cookie banner (cookie consent banner) collects user consent for cookies and tracking. It:

  1. Informs users about cookies and tracking
  2. Gets consent before setting non-essential cookies
  3. Provides control to accept, reject, or customize
  4. Respects choices by blocking scripts until consent

Learn more: What is a Cookie Banner?

Cookie Banners vs. Full Compliance

What a Cookie Banner Does

A cookie banner handles consent collection:

  • Displays notice about cookies
  • Collects user preferences
  • Blocks non-essential scripts until consent
  • Stores consent choices

What Full Compliance Requires

Cookie consent is one part of privacy compliance. Full compliance also needs:

  • Privacy Policy - Document explaining data practices
  • Data Processing Records - Internal documentation
  • User Rights Handling - Data access/deletion processes

TinyConsent handles cookie consent. For privacy policies: tinyconsent.com/privacy-policy-generator

GDPR Cookie Consent Requirements

The GDPR requires for cookies:

  • Get consent BEFORE setting non-essential cookies
  • Easy reject option required
  • Granular consent options (analytics, marketing)
  • No pre-ticked boxes

Learn more: GDPR Cookie Requirements

CCPA Requirements

The CCPA requires:

  • Disclose data collection practices
  • "Do Not Sell" option for users
  • Non-discrimination for opt-outs

Learn more: CCPA Cookie Requirements

FAQ

How do I get a script ID?

  1. Visit tinyconsent.com/cookie-banner-generator
  2. Enter your email
  3. Copy your script ID

Does this work with Next.js 13+ App Router?

Yes! Add the component to your root layout's <head>.

Does it block Google Analytics?

Yes. TinyConsent blocks GA4, Facebook Pixel, and other trackers until consent is given.

Does it support Google Consent Mode v2?

Yes. Google Consent Mode is automatically integrated.

Can I customize the banner?

Yes! All customization is done in your TinyConsent Dashboard - no code changes needed.

Do I need a privacy policy?

Yes. Generate one free: tinyconsent.com/privacy-policy-generator

Is it SSR compatible?

Yes. Works with Next.js, Remix, Gatsby, and other SSR frameworks.

Troubleshooting

Banner not appearing

  1. Verify your script ID is correct
  2. Check browser console for errors
  3. Test in incognito mode (clears previous consent)
  4. Ensure no ad blockers are interfering

Hydration warnings in Next.js

The component is designed to avoid hydration issues. If you see warnings, ensure you're using the latest version.

TypeScript errors

Make sure you have @types/react installed:

npm install -D @types/react

TypeScript

Full TypeScript support:

import { 
  TinyConsentScript,
  TinyConsentScriptProps,
  useTinyConsent,
  UseTinyConsentResult,
  getTinyConsentScriptUrl
} from 'tinyconsent-react';

Related Packages

Resources

License

MIT © TinyConsent


Keywords: cookie banner react, react cookie consent, cookie banner npm, GDPR react, CCPA react, cookie consent component, next.js cookie banner, gatsby cookie banner, one line cookie banner, lightweight cookie consent, cookie banner generator