📜  带有反应挂钩的暗模式 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:29.307000             🧑  作者: Mango

代码示例1
// 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"));
  },[]);