mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-21 07:26:49 +00:00
Code🤣
This commit is contained in:
19
lib/theme.js
Normal file
19
lib/theme.js
Normal 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)
|
||||
Reference in New Issue
Block a user