UNPKG

0x1

Version:

0x1: Lightning-fast web framework for JavaScript/TypeScript with zero overhead and maximum performance, powered by Bun

28 lines (24 loc) 712 B
import { useEffect, useState } from '0x1'; export function useTheme() { const [isDark, setIsDark] = useState(() => { if (typeof window !== 'undefined') { const saved = localStorage.getItem('0x1-dark-mode'); if (saved) return saved === 'dark'; } return false; }); const toggleTheme = () => { const newIsDark = !isDark; setIsDark(newIsDark); document.documentElement.classList.toggle('dark', newIsDark); localStorage.setItem('0x1-dark-mode', newIsDark ? 'dark' : 'light'); }; useEffect(() => { document.documentElement.classList.toggle('dark', isDark); }, [isDark]); return { isDark, theme: isDark ? 'dark' : 'light', toggleTheme }; }