Spaces:
Sleeping
Sleeping
| import { createContext, useContext, useState, useEffect } from 'react'; | |
| const ThemeContext = createContext(); | |
| export function ThemeProvider({ children }) { | |
| const [theme, setTheme] = useState(() => { | |
| return localStorage.getItem('llm-compare-theme') || 'light'; | |
| }); | |
| useEffect(() => { | |
| document.documentElement.setAttribute('data-theme', theme); | |
| localStorage.setItem('llm-compare-theme', theme); | |
| }, [theme]); | |
| const toggleTheme = () => setTheme(t => t === 'light' ? 'dark' : 'light'); | |
| return ( | |
| <ThemeContext.Provider value={{ theme, toggleTheme, isLight: theme === 'light', isDark: theme === 'dark' }}> | |
| {children} | |
| </ThemeContext.Provider> | |
| ); | |
| } | |
| export const useTheme = () => useContext(ThemeContext); | |