JSPM

@alikia/dark-theme-hook

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q38167F
  • License MIT

A React hook that responds to prefers-color-scheme

Package Exports

  • @alikia/dark-theme-hook
  • @alikia/dark-theme-hook/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@alikia/dark-theme-hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Dark Theme Hook

Dark Theme Hook is a custom React hook that allows you to detect the user's preferred color scheme, specifically whether they have enabled dark mode. This hook listens for changes in the user's system preferences and updates accordingly.

Installation

You can install Dark Theme Hook using your preferred package manager:

npm install @alikia/dark-theme-hook
yarn add @alikia/dark-theme-hook
pnpm add @alikia/dark-theme-hook
bun add @alikia/dark-theme-hook

Usage

To use the Dark Theme Hook in your React application, simply import and call the hook within your functional components:

import useDarkTheme from '@alikia/dark-theme-hook';

function MyComponent() {
    const isDarkMode = useDarkTheme();

    return (
        <div className={isDarkMode ? 'dark-mode' : 'light-mode'}>
            <h1>Dark Mode Detection</h1>
            <p>Dark mode is {isDarkMode ? 'enabled' : 'disabled'}.</p>
        </div>
    );
}

export default MyComponent;