UAIDE / src /hooks /useTheme.js
ATS-27's picture
Upload folder using huggingface_hub
af980d7 verified
Raw
History Blame Contribute Delete
691 Bytes
import { useEffect, useState } from 'react';
const STORAGE_KEY = 'uaide-theme';
function getInitialTheme() {
if (typeof window === 'undefined') return 'dark';
const stored = window.localStorage.getItem(STORAGE_KEY);
if (stored === 'light' || stored === 'dark') return stored;
return 'dark';
}
export function useTheme() {
const [theme, setTheme] = useState(getInitialTheme);
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme);
window.localStorage.setItem(STORAGE_KEY, theme);
}, [theme]);
const toggleTheme = () => {
setTheme((current) => (current === 'dark' ? 'light' : 'dark'));
};
return { theme, toggleTheme, setTheme };
}