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

next-theme-handler

v1.0.0

Published

A lightweight theme switcher for React with system preference detection

Downloads

8

Readme

🌗 next-theme-handler

npm version bundle size license CI Status

A lightweight, performant theme switcher for React applications with system preference detection and CSS variables support.

Demo Animation

✨ Features

  • 🌓 Three theme modes: Light, Dark, and System preference
  • 🎨 CSS Variables based: Bring your own theme definitions
  • Optimized: Zero dependencies, ~2KB gzipped
  • 💾 Persistent: Automatically saves user preference
  • 📱 Responsive: Syncs with system color scheme changes
  • ⚛️ React 18+ Ready: Works with all modern React versions
  • 🏷 TypeScript Support: Full type definitions included
  • 🖥 SSR Compatible: Works with Next.js, Remix, etc.

📦 Installation

# npm
npm install next-theme-handler

# yarn
yarn add next-theme-handler

# pnpm
pnpm add next-theme-handler

🎨 Theme Configuration

/* include in global css  or  your root css file */
:root[data-theme="light"] {
  --bg: #ffffff;
  --text: #333333;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e2e8f0;
  --card-bg: #f8fafc;
  --error: #dc2626;
}

:root[data-theme="dark"] {
  --bg: #1a1a1a;
  --text: #f8f8f8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --border: #2d3748;
  --card-bg: #1e293b;
  --error: #ef4444;
}

Advanced Setup (Next.js)

//_ThemeProviderWrapper.tsx
"use client"; // Mark as Client Component

import { ThemeProvider } from "next-theme-handler";
import { useEffect, useState } from "react";

export default function ThemeProviderWrapper({
  children,
}: {
  children: React.ReactNode;
}) {
  // Prevent SSR mismatch by showing nothing until mounted
  const [mounted, setMounted] = useState(false);

  useEffect(() => {
    setMounted(true);
  }, []);

  if (!mounted) {
    return null;
  }

  return (
    <ThemeProvider
      defaultTheme="system"
      storageKey="next-app-theme"
    >
      {children}
    </ThemeProvider>
  );
}
//_layout.tsx or ur root tsx file
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import ThemeProviderWrapper from "@/components/ThemeProviderWrapper";

const geistSans = Geist({
  variable: "--font-geist-sans",
  subsets: ["latin"],
});

const geistMono = Geist_Mono({
  variable: "--font-geist-mono",
  subsets: ["latin"],
});

export const metadata: Metadata = {
  title: "Foo-Boo",
  description: "Generated by Harsha",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={`${geistSans.variable} ${geistMono.variable} antialiased`} >
        <ThemeProviderWrapper>{children}</ThemeProviderWrapper>     
       </body>
    </html>
  );

}

🎮 Using the Hook

"use client";

import { useTheme } from "next-theme-handler";

export default function ThemeSwitcher() {
  const { theme, setTheme } = useTheme();

  return (
    <div className="flex gap-2">
      <button 
        onClick={() => setTheme("light")}
        className={`px-3 py-1 rounded ${theme === "light" ? "bg-blue-500 text-white" : "bg-gray-200"}`}
      >
        Light
      </button>
      <button
        onClick={() => setTheme("dark")}
        className={`px-3 py-1 rounded ${theme === "dark" ? "bg-blue-500 text-white" : "bg-gray-800 text-white"}`}
      >
        Dark
      </button>
      <button
        onClick={() => setTheme("system")}
        className="px-3 py-1 bg-gray-500 text-white rounded"
      >
        System
      </button>
    </div>
  );
}

🛠 API Reference

| Prop | Type | Default | Description | |--------------|---------------------|-----------|-----------------------------------------------------------------------------| | defaultTheme | 'light'|'dark'|'system' | 'light' | Default theme if no preference exists | | storageKey | string | 'theme' | localStorage key | | ssr | boolean | false | Enable SSR support |

🤝 Contributing

  1. Fork the repository.
  2. Create a branch (git checkout -b feature/your-feature).
  3. Commit changes (git commit -am 'Add feature').
  4. Push (git push origin feature/your-feature).
  5. Open a PR.

📜 License

MIT © Harzsha