Dark mode in reactjs code example
Example 1: react dark mode npm
$ npm i use-dark-mode
Example 2: dark mode with react hooks
// DarkMode/index.js
const DarkModeToggle = () => {
const [isDark, setIsDark] = useState(localStorage.getItem("theme") === "dark" ? true : false);
useEffect(() => {
document
.getElementsByTagName("HTML")[0]
.setAttribute("data-theme", localStorage.getItem("theme"));
},[]);