# use-prefers-color-scheme

> React hook for determining the preferred color scheme

Latest version **1.1.3** (published 2023-01-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-prefers-color-scheme
pnpm add use-prefers-color-scheme
yarn add use-prefers-color-scheme
bun add use-prefers-color-scheme
```

## 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.1.3 |
| Published | 2023-01-31 |
| First published | 2020-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | rfoel |
| Maintainers | rfoel |

## Links

- npm: https://www.npmjs.com/package/use-prefers-color-scheme
- Repository: https://github.com/rfoel/use-prefers-color-scheme
- Homepage: https://github.com/rfoel/use-prefers-color-scheme#readme
- Issues: https://github.com/rfoel/use-prefers-color-scheme/issues
- npm.io page: https://npm.io/package/use-prefers-color-scheme

## Recent versions

- 1.1.3 (latest) — 2023-01-31
- 1.1.3-6b0b94a.4 (next) — 2023-01-31
- 1.1.3-6b0b94a.3 — 2023-01-31
- 1.1.3-6b0b94a.2 — 2023-01-31
- 1.1.3-6b0b94a.1 — 2023-01-31
- 1.1.3-6b0b94a.0 — 2023-01-31
- 1.1.3-0943d0e.0 — 2023-01-31
- 1.1.2 — 2023-01-23
- 1.1.1 — 2022-10-19
- 1.1.0 — 2022-10-17
- 1.0.0 — 2022-10-05
- 0.1.2-rc.4 — 2022-10-05
- 0.1.2-rc.3 — 2022-10-05
- 0.1.2-rc.2 — 2022-10-05
- 0.1.2-rc.1 — 2022-10-05
- … 3 more at https://npm.io/package/use-prefers-color-scheme/versions

## README

# use-prefers-color-scheme

> React hook for determining the preferred color scheme

[![NPM](https://img.shields.io/npm/v/use-prefers-color-scheme.svg)](https://www.npmjs.com/package/use-prefers-color-scheme)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Features:

- SSR support
- Written in Typescript

## Install

```bash
npm install --save use-prefers-color-scheme
```

## Usage

> **Tip** When rendered in node (SSR) the hook returns `no-preference`.

```jsx
import React from 'react'

import usePrefersColorScheme from 'use-prefers-color-scheme'

const App = () => {
  const prefersColorScheme = usePrefersColorScheme()
  const isDarkMode = prefersColorScheme === 'dark'

  return (
    <div>You are using {isDarkMode ? 'Dark Mode 🌚' : 'Light Mode 🌞'}!</div>
  )
}
```


## Online Demo

[![Open Codesanbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/use-prefers-color-scheme-example-xb134y?file=/src/App.js)


## License

MIT © [rfoel](https://github.com/rfoel)

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