team-9/app/src/hooks/useTheme.tsx

29 lines
626 B
TypeScript
Raw Normal View History

2025-08-02 02:08:59 +02:00
// 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,
};
}