# react-dark-theme-context

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

Latest version **1.0.0** (published 2023-12-13) · 0 weekly downloads

## Install

```sh
npm install react-dark-theme-context
pnpm add react-dark-theme-context
yarn add react-dark-theme-context
bun add react-dark-theme-context
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-12-13 |
| First published | 2023-12-13 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vadim Taits |
| Maintainers | vtaits |
| Keywords | react, theme, switch, switching, dark, prefers, color, scheme, prefers-color-scheme |

## Links

- npm: https://www.npmjs.com/package/react-dark-theme-context
- Repository: https://github.com/vtaits/react-dark-theme-context
- Issues: https://github.com/vtaits/react-dark-theme-context/issues
- npm.io page: https://npm.io/package/react-dark-theme-context

## Dependencies (2)

- [use-local-storage-state](https://npm.io/package/use-local-storage-state.md) ^19.1.0
- [use-prefers-color-scheme](https://npm.io/package/use-prefers-color-scheme.md) ^1.1.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-12-13

## README

# react-dark-theme-context

[![NPM](https://img.shields.io/npm/v/react-dark-theme-context.svg)](https://www.npmjs.com/package/react-dark-theme-context)
![dependencies status](https://img.shields.io/librariesio/release/npm/react-dark-theme-context)

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`.

```tsx
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.

```tsx
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;

---
_Source: https://npm.io/package/react-dark-theme-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
