import { useState } from "preact/hooks"; import { IS_BROWSER } from "fresh/runtime"; export default function ThemeToggle() { const [theme, setTheme] = useState(() => { if (!IS_BROWSER) return "light"; return document.documentElement.dataset.theme ?? "light"; }); const toggleTheme = () => { setTheme((prev) => { const theme = prev === "light" ? "dark" : "light"; document.documentElement.setAttribute("data-theme", theme); localStorage.setItem("theme", theme); return theme; }); }; return ( ); }