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

react-cookie-consent_test2

v0.1.0-beta.112

Published

React components to integrate TrustArc Cookie Consent Manager into React and Next.js apps

Readme

TrustArc React Hook

Overview

The useTrustArc React hook provides an easy way to integrate TrustArc Consent Manager into your React applications. It dynamically loads the TrustArc consent script, ensures the banner is created, and provides a "Cookie Preferences" link.

This package is designed for TrustArc customers who need to seamlessly integrate consent management into their web applications.

Beta Release

Please note that this is a beta release. While we have tested the package, there may still be some issues. Use it at your own risk and report any bugs or issues you encounter. Your feedback is valuable in helping us improve the package.


Installation

You can install this package via npm or yarn (assuming it's published as a package or included in your project).

npm install @trustarc/react-cookie-consent
# or
yarn add @trustarc/react-cookie-consent

Building the Component

Before using or publishing the package, ensure it's built properly:

npm install  # Install dependencies
npm run build  # Generate the production-ready bundle

Using TrustArc in a Next.js Project

To integrate TrustArc Cookie Consent Manager in a Next.js project, modify the layout.tsx file to ensure the consent banner and script are loaded globally.

Steps to Integrate TrustArc in Next.js

  1. Install Dependencies (if needed)

    npm install next react react-dom
  2. Modify app/layout.tsx in your Next.js project:

    "use client";
    import { useTrustArc } from "@trustarc/react-cookie-consent";
    import Link from "next/link";
    
    export default function RootLayout({ children }: { children: React.ReactNode }) {
      const { TrustArcScript, TrustArcConsentBanner, TrustArcCookiePreferencesLink } = useTrustArc("trustarc.com", {
        ccmVersion: "advanced",
        debug: true,
      });
    
      return (
        <html lang="en">
          <body>
            <TrustArcScript />
            <TrustArcConsentBanner />
            {children}
            <nav>
              <Link href="/">Home</Link>
              <Link href="/privacy-policy">Privacy Policy</Link>
            </nav>
            <footer>
              <TrustArcCookiePreferencesLink />
            </footer>
          </body>
        </html>
      );
    }

Using TrustArc in a React Project

1. App.tsx (Main Application Component)

import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Home from "./Home";
import About from "./About";
import Layout from "./Layout";
import { useTrustArc } from "@trustarc/react-cookie-consent";

const App = () => {
  const { TrustArcConsentBanner, TrustArcCookiePreferencesLink, TrustArcScript } = useTrustArc("trustarc.com", {
    debug: true,
  });

  return (
    <Router>
      <TrustArcScript />
      <Layout>
        <TrustArcConsentBanner />
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
        </Routes>
      </Layout>
      <footer>
        <TrustArcCookiePreferencesLink />
      </footer>
    </Router>
  );
};

export default App;

Conclusion

This useTrustArc hook simplifies the integration of TrustArc Consent Manager in React applications. It provides a reliable solution that:

  • Dynamically injects the script & ensures proper loading.
  • Prevents multiple re-injections.
  • Handles React Strict Mode behavior.
  • Supports debugging for easier troubleshooting.

If you encounter any issues, enable debug: true and check the console logs.