# use-prefer-dark-mode

> Small react hook to determine if your user prefers dark mode on their system.

Latest version **1.0.4** (published 2019-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-prefer-dark-mode
pnpm add use-prefer-dark-mode
yarn add use-prefer-dark-mode
bun add use-prefer-dark-mode
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-10-09 |
| First published | 2019-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Isaiah Smith |
| Maintainers | jordankid93 |
| Keywords | react, hook, dark mode |

## Links

- npm: https://www.npmjs.com/package/use-prefer-dark-mode
- Repository: https://github.com/jordankid93/use-prefer-dark-mode
- Homepage: https://github.com/jordankid93/use-prefer-dark-mode#readme
- Issues: https://github.com/jordankid93/use-prefer-dark-mode/issues
- npm.io page: https://npm.io/package/use-prefer-dark-mode

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^16.10.2

## 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.4 (latest) — 2019-10-09
- 1.0.3 — 2019-10-09
- 1.0.2 — 2019-10-09
- 1.0.0 — 2019-10-09
- 0.1.0 — 2019-10-09

## README

# use-prefer-dark-mode
Small react hook to determine if your user prefers dark mode on their system.

A lot of packages that deal with determining if you should use dark mode come with unneeded components, Contexts Providers & Consumers, configs objects you have to pass in, etc. 

This one is simple. It only tells you if your user __*prefers*__ dark mode based on their os settings. We let __*you*__ determine where and how you deal with that preference. 🤙🏽

## install
```
npm install --save use-prefer-dark-mode
# or
yarn add use-prefer-dark-mode
```
### TypeScript Compatible

`use-prefer-dark-mode` is written in TypeScript so no need to install any addition types 👍🏽


## usage
```javascript
import React from "react"
import usePDM from "use-prefer-dark-mode"

const HelloWorld = () => {
  const prefersDarkMode = usePDM() // Boolean of if the user prefers dark mode according to their OS system
  
  const darkStyles = {
    backgroundColor: "black",
    color: "white"
  }
  
  const lightStyles = {
    backgroundColor: "white",
    color: "black"
  }
  
  const styles = prefersDarkMode ? darkStyles : lightStyles
  
  return <div style={styles} >Hello, World!</div>
}
```

## Testing
### Jest Mock
`use-prefer-dark-mode` uses `window.mediaMatch` to see if the user prefers dark mode or not. If you use the [Jest](https://jestjs.io) testing library you might need to [mock this function](https://jestjs.io/docs/en/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom).

### Help write tests
If you are interested in helping out with tests for this package, simply open a PR and let's work together!

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