@redredgroup/react-browser-theme-detect
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

🪄 React Browser Theme Detect

NPM

Usage

Add the dependency:

NPM

npm install @redredgroup/react-browser-theme-detect

Yarn

yarn add @redredgroup/react-browser-theme-detect

Example

Import the package:

import { isTheme, isThemeLight, isThemeDark } from "@redredgroup/react-browser-theme-detect";

Returns the String value for dark mode or light mode:

const themeString = isTheme();
// Returns "light" or "dark"

When the Boolean value for dark mode detection is required,

const isDark = isThemeDark();
// If it is in dark mode, return true or false
const isLight = isThemeLight();
// If it is in dark mode, return true or false

💡 Browser support

This package only works in browsers that natively support @media (prefers-color-scheme), so it just returns "light" in unsupported browsers. Current browser support

Readme

Keywords

none

Package Sidebar

Install

npm i @redredgroup/react-browser-theme-detect

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

4.32 kB

Total Files

9

Last publish

Collaborators

  • jieey1140