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

better-themes

v1.1.0

Published

A theme provider for React

Readme

better-themes

A theme provider for React

Bundle size npm version License

Better Themes Preview

Features

  • Zero flash on load - Prevents theme flash during page load (SSR/SSG safe)
  • System preference detection - Automatically detects and respects user's system theme preference via prefers-color-scheme
  • Cross-tab synchronization - Theme changes sync across browser tabs and windows
  • Themed browser UI - Sets color-scheme CSS property for native browser UI elements
  • Custom themes - Support for multiple custom themes beyond light/dark
  • Flexible styling - Use class or data attributes (works with Tailwind CSS)
  • TypeScript - Fully typed with TypeScript
  • Framework agnostic - Works with Next.js, Remix, Vite, TanStack Start, Waku, and more

Installation

npm install better-themes
# or
pnpm add better-themes
# or
yarn add better-themes
# or
bun add better-themes

Quick Start

Wrap your app with ThemeProvider at the root of your application.

Next.js (App Router)

For React Server Components, import from better-themes/rsc:

import { ThemeProvider } from "better-themes/rsc";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body>
        <ThemeProvider>
          {children}
        </ThemeProvider>
      </body>
    </html>
  );
}

Vite, TanStack Start, & Others

For client-side applications or other frameworks:

import { ThemeProvider } from "better-themes";

function App() {
  return (
    <ThemeProvider>
      {/* Your app content */}
    </ThemeProvider>
  );
}

Important: Add suppressHydrationWarning to your <html> tag to prevent hydration warnings.

Usage

Access the current theme and change it with the useTheme hook:

"use client"

import { useTheme } from "better-themes";

function ThemeToggle() {
  const { theme, setTheme, themes } = useTheme();

  return (
    <div>
      <p>Current theme: {theme}</p>
      <button onClick={() => setTheme("light")}>Light</button>
      <button onClick={() => setTheme("dark")}>Dark</button>
      <button onClick={() => setTheme("system")}>System</button>
    </div>
  );
}

Configuration

The ThemeProvider accepts the following props:

  • themes - List of available theme names (default: ["light", "dark"])
  • defaultTheme - Default theme when no preference is saved (default: "system" if enableSystem is true, else "light")
  • storageKey - localStorage key for storing theme preference (default: "theme")
  • forcedTheme - Force a specific theme (overrides user preference)
  • enableSystem - Enable system theme detection (default: true)
  • enableColorScheme - Set color-scheme CSS property (default: true)
  • attribute - HTML attribute to modify (default: "class", can be "class" or "data-*")
  • value - Map theme names to attribute values
  • disableTransitionOnChange - Disable CSS transitions on switch (default: false)
  • nonce - Nonce for CSP headers

Styling with Tailwind CSS

Use class-based dark mode in Tailwind:

<ThemeProvider attribute="class">
  {children}
</ThemeProvider>

Then use dark variants:

<h1 className="text-black dark:text-white">
  Hello World
</h1>

This project is deployed on Netlify

Documentation

For complete documentation, examples, and recipes, visit https://better-themes.netlify.app

Credits

This project is inspired by and based on next-themes by Paco Coursey and tanstack-theme-kit by augiwan.

License

MIT