skeletal layout, theme functionality, mobile/desktop responsive, autoscroll
This commit is contained in:
21
src/hooks/useTheme.ts
Normal file
21
src/hooks/useTheme.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
|
||||
export type ThemeKey = "a" | "b" | "c" | "d" | "e";
|
||||
|
||||
|
||||
export function useTheme() {
|
||||
const [theme, setTheme] = useState<ThemeKey>(() => {
|
||||
const saved = (typeof window !== "undefined" && localStorage.getItem("theme")) as ThemeKey | null;
|
||||
return saved ?? "a";
|
||||
});
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
localStorage.setItem("theme", theme);
|
||||
}, [theme]);
|
||||
|
||||
|
||||
return { theme, setTheme };
|
||||
}
|
||||
Reference in New Issue
Block a user