mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-05 07:56:15 +02:00
feat: implement dark mode
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export const useLocalStorage = (name: string, initialValue: string) => {
|
||||
const windowGlobal = typeof window !== "undefined" && window
|
||||
const [value, setValue] = useState(() => {
|
||||
if (windowGlobal) {
|
||||
const currentValue = windowGlobal.localStorage.getItem(name)
|
||||
return currentValue ? JSON.parse(currentValue) : initialValue
|
||||
}
|
||||
return initialValue
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (windowGlobal) {
|
||||
windowGlobal.localStorage.setItem(name, JSON.stringify(value))
|
||||
}
|
||||
}, [name, value, windowGlobal])
|
||||
|
||||
return [value, setValue]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { useContext } from "react"
|
||||
import { IThemeContext, ThemeContext } from "../ThemeProvider"
|
||||
|
||||
export default function useTheme(): IThemeContext {
|
||||
const themeContext = useContext(ThemeContext)
|
||||
|
||||
if (!themeContext) {
|
||||
throw Error("Need context")
|
||||
}
|
||||
|
||||
return themeContext
|
||||
}
|
||||
Reference in New Issue
Block a user