app first commit
This commit is contained in:
parent
0e16d3e6be
commit
4441012687
45 changed files with 12987 additions and 0 deletions
28
app/src/hooks/useTheme.tsx
Normal file
28
app/src/hooks/useTheme.tsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
// src/hooks/useTheme.ts
|
||||
import { useEffect } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { themeAtom } from "../atoms";
|
||||
|
||||
const ALL_THEMES = ["light", "dark", "red"];
|
||||
|
||||
export function useTheme() {
|
||||
const [theme, setTheme] = useAtom(themeAtom);
|
||||
|
||||
useEffect(() => {
|
||||
const body = document.body;
|
||||
ALL_THEMES.forEach((t) => body.classList.remove(t));
|
||||
body.classList.add(theme);
|
||||
console.log('set ', theme)
|
||||
}, [theme]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
setTheme((prev) => (prev === "light" ? "dark" : "light"));
|
||||
};
|
||||
|
||||
return {
|
||||
theme,
|
||||
setTheme,
|
||||
toggleTheme,
|
||||
themes: ALL_THEMES,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue