rebuild portfolio: Next.js 16, React 19, Tailwind v4, homelab page, CI/CD
Build and Deploy / deploy (push) Successful in 1m0s
Build and Deploy / deploy (push) Successful in 1m0s
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useEffect, useState } from "react";
|
||||
|
||||
type ThemeContextType = {
|
||||
isDark: boolean;
|
||||
toggle: () => void;
|
||||
};
|
||||
|
||||
const ThemeContext = createContext<ThemeContextType>({
|
||||
isDark: true,
|
||||
toggle: () => {},
|
||||
});
|
||||
|
||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
const [isDark, setIsDark] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const stored = localStorage.getItem("lerko96-dark-mode");
|
||||
const dark = stored === null ? true : stored === "true";
|
||||
setIsDark(dark);
|
||||
document.documentElement.classList.toggle("dark", dark);
|
||||
}, []);
|
||||
|
||||
function toggle() {
|
||||
const next = !isDark;
|
||||
setIsDark(next);
|
||||
localStorage.setItem("lerko96-dark-mode", String(next));
|
||||
document.documentElement.classList.toggle("dark", next);
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ isDark, toggle }}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTheme() {
|
||||
return useContext(ThemeContext);
|
||||
}
|
||||
Reference in New Issue
Block a user