UNPKG

stackpress

Version:

Incept is a content management framework.

19 lines (18 loc) 703 B
import { jsx as _jsx } from "react/jsx-runtime"; import { useState, useEffect } from 'react'; import { getCookie, setCookie } from 'cookies-next'; import ThemeContext from './ThemeContext'; export default function ThemeProvider(props) { const { children, theme: init = 'light' } = props; const [theme, setTheme] = useState(init); const toggle = () => { const newTheme = theme === 'light' ? 'dark' : 'light'; setTheme(newTheme); setCookie('theme', newTheme); }; const value = { theme, toggle }; useEffect(() => { setTheme(getCookie('theme') || 'light'); }, []); return (_jsx(ThemeContext.Provider, { value: value, children: children })); }