A hook to manage dark mode state and apply dark mode styling based on user preference and localStorage.
- None
- An array containing:
- A boolean indicating if dark mode is enabled.
- A function to toggle dark mode.
/* body.css file:
body.dark-mode {
background-color: #333;
}
*/
import useDarkMode from "./useDarkMode"
import "./body.css"
export default function DarkModeComponent() {
const [darkMode, setDarkMode] = useDarkMode()
return (
<button
onClick={() => setDarkMode(prevDarkMode => !prevDarkMode)}
style={{
border: `1px solid ${darkMode ? "white" : "black"}`,
background: "none",
color: darkMode ? "white" : "black",
}}
>
Toggle Dark Mode
</button>
)
}