dark mode with react hooks

Solutions on MaxInterview for dark mode with react hooks by the best coders in the world

showing results for - "dark mode with react hooks"
Milan
02 Oct 2019
1// DarkMode/index.js
2
3const DarkModeToggle = () => {
4  const [isDark, setIsDark] = useState(localStorage.getItem("theme") === "dark" ? true : false);
5  useEffect(() => {
6    document
7    .getElementsByTagName("HTML")[0]
8    .setAttribute("data-theme", localStorage.getItem("theme"));
9  },[]);
10