JSPM

zzoo-react-theme

0.0.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q28650F
  • License MIT

A React theme provider with SSR support for light/dark mode switching

Package Exports

  • zzoo-react-theme

Readme

@your-org/react-theme

A React theme provider with SSR support for light/dark mode switching.

Features

  • ๐ŸŒ“ Light/Dark theme switching
  • ๐Ÿ”„ Persistent theme storage via cookies
  • โšก SSR/Next.js compatible
  • ๐ŸŽฏ TypeScript support
  • ๐Ÿชถ Lightweight (no dependencies)
  • ๐Ÿงช Fully tested

Installation

npm install @your-org/react-theme

Usage

Client-side usage

import { ThemeProvider, useTheme } from '@your-org/react-theme'

function App() {
  return (
    <ThemeProvider>
      <YourApp />
    </ThemeProvider>
  )
}

function ThemeToggle() {
  const { theme, setTheme } = useTheme()
  
  return (
    <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
      Current: {theme}
    </button>
  )
}

Server-side usage (Next.js)

import { ServerThemeWrapper } from '@your-org/react-theme'
import { cookies } from 'next/headers'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <ServerThemeWrapper cookies={cookies}>
          {children}
        </ServerThemeWrapper>
      </body>
    </html>
  )
}

CSS Integration

The theme is applied via data-theme attribute on document.documentElement:

[data-theme="light"] {
  --bg-color: white;
  --text-color: black;
}

[data-theme="dark"] {
  --bg-color: black;
  --text-color: white;
}

API

ThemeProvider

Prop Type Description
theme "light" | "dark" Optional initial theme
children ReactNode Child components

useTheme()

Returns an object with:

  • theme: Current theme ("light" \| "dark" \| undefined)
  • setTheme: Function to update theme

ServerThemeWrapper

Prop Type Description
cookies () => Promise<ReadonlyRequestCookies> Next.js cookies function
children ReactNode Child components

License

MIT