Simple-to-use React hook to add light/dark modes to your React app.
✅️ Respects user OS preference
✅️️ Respects manual theme overrides
✅️ Snaps back to OS preference if needed
✅️ SSR ready
✅️ Syncs theme across tabs and windows
npm i @madebysid/usetheme
--OR--
yarn add @madebysid/usetheme
- Use the
useThemehook whenever you need access to the theme:
import { useTheme } from "useTheme";
function Component() {
const { theme, setTheme } = useTheme();
return (
<>
Current theme: {theme}
<button onClick={setTheme("dark")}>🌚</button>
<button onClick={setTheme("light")}>🌝</button>
</>
);
}- Install dependencies:
yarn - Start dev server:
yarn dev
- Install playwright browsers:
yarn playwright install(Only needed once) - Run tests:
yarn test