mirror of
https://github.com/cupcakearmy/use-light-switch.git
synced 2024-12-21 23:46:26 +00:00
React Hook for easy dark mode integration
lib | ||
test | ||
.gitignore | ||
.npmignore | ||
.prettierrc | ||
LICENSE | ||
package.json | ||
README.md | ||
tsconfig.json |
use-light-switch
React hook for dark mode.
🌈 Features
- Typescript compatible
- 0 Dependencies
- Tiny ~0.7kB
- React Hooks
Installation
npm i use-light-switch
🤔 Motivation
There was no library with typings 🤕
🚀 Quickstart
import React from 'react'
import ReactDOM from 'react-dom'
import { useModeSelector } from 'use-light-switch'
const App: React.FC = () => {
const selected = useModeSelector({
light: { color: 'green', name: 'Light' },
dark: { color: 'red', name: 'Dark' },
unset: { color: 'blue', name: 'Unset' },
})
return <div>
<h3>Selector</h3>
<div style={{
padding: '1em 2em',
backgroundColor: selected.color
}}>
{selected.name}
</div>
</div>
}
ReactDOM.render(<App />, window.document.getElementById('root'))