react-dark-theme-context
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-dark-theme-context

NPM dependencies status

Tools to detect, switch and save dark theme for react applications

ThemeProvider

This is the component that detects the setted theme by the browser settings and stores it in localStorage.

import { ThemeProvider } from "react-dark-theme-context";

// ...

<ThemeProvider>
  {yourReactApplication}
</ThemeProvider>

Props

  • localStorageKey - string - The key of local storage to save the selected theme.
  • defaultTheme - "dark" | "light" | "no-preference" - Theme setted by default. Can be "no-preference" for automatical detection.
  • defaultDisplayTheme - "dark" | "light" - Theme displayed if setted theme is "no-preference";
  • children

useTheme

This is the hook to get and change the current theme.

import { useTheme } from "react-dark-theme-context";

// ...

const {
  displayTheme,
  setTheme,
  theme,
} = useTheme();
  • displayTheme - "dark" | "light" - Theme that currently displayed.
  • theme - "dark" | "light" | "no-preference" - Theme that currently setted. Can be no-preference for automatical detection.
  • setTheme - (nextTheme: ThemeType) => void - Theme change function;

Package Sidebar

Install

npm i react-dark-theme-context

Weekly Downloads

1

Version

1.0.0

License

none

Unpacked Size

18.5 kB

Total Files

9

Last publish

Collaborators

  • vtaits