Something went wrong. Try again.
FlockOff is a mass-block tool for the Atmosphere flockoff.app
Something went wrong. Try again.
1.0 kB · 41 lines
TSX
at master
123456789101112131415161718192021222324252627282930313233343536373839404142'use client'
import { createContext, useContext, useEffect, useState } from 'react'
type Theme = 'light' | 'dark'
const ThemeContext = createContext<{ theme: Theme toggle: () => void}>({ theme: 'light', toggle: () => {} })
export function ThemeProvider({ children }: { children: React.ReactNode }) { const [theme, setTheme] = useState<Theme>('light')
useEffect(() => { const stored = localStorage.getItem('flockoff-theme') as Theme | null if (stored === 'dark') { setTheme('dark') document.documentElement.classList.add('dark') } }, [])
const toggle = () => { setTheme(prev => { const next = prev === 'light' ? 'dark' : 'light' localStorage.setItem('flockoff-theme', next) document.documentElement.classList.toggle('dark', next === 'dark') return next }) }
return ( <ThemeContext.Provider value={{ theme, toggle }}> {children} </ThemeContext.Provider> )}
export function useTheme() { return useContext(ThemeContext)}