This commit is contained in:
tangly1024
2021-09-27 09:33:21 +08:00
parent 22ca7f6d63
commit dfc0f645d4
76 changed files with 3650 additions and 2 deletions

19
lib/theme.js Normal file
View File

@@ -0,0 +1,19 @@
import { useContext, createContext, useState, useEffect } from 'react'
import localStorage from 'localStorage'
const ThemeContext = createContext()
export function ThemeProvider ({ children }) {
// 初始值
const defaultTheme = localStorage.getItem('theme')
const [theme, changeTheme] = useState()
useEffect(() => {
changeTheme(defaultTheme)
})
return (
<ThemeContext.Provider value={{ theme, changeTheme }}>{children}</ThemeContext.Provider>
)
}
export const useTheme = () => useContext(ThemeContext)