Files
blocnote/app/hooks/useTheme.ts
T
Puechberty Arthur 63e6c64077 Add SVG assets and TypeScript configuration
- Created a new SVG for the Open Graph image (og-image.svg) with a gradient background and text elements.
- Added Vercel logo SVG (vercel.svg) for deployment branding.
- Introduced a window icon SVG (window.svg) for UI representation.
- Initialized TypeScript configuration file (tsconfig.json) with strict settings and module resolution for a React project.
2026-03-30 19:25:43 +02:00

29 lines
832 B
TypeScript

"use client";
import { useState, useEffect } from "react";
import { Theme } from "../types";
export function useTheme() {
const [theme, setTheme] = useState<Theme>("light");
useEffect(() => {
const saved = localStorage.getItem("blocnote-theme") as Theme | null;
if (saved) {
// Reading persisted theme must happen on client after mount.
// eslint-disable-next-line react-hooks/set-state-in-effect
setTheme(saved);
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
setTheme("dark");
}
}, []);
useEffect(() => {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("blocnote-theme", theme);
}, [theme]);
const toggleTheme = () => setTheme((t) => (t === "light" ? "dark" : "light"));
return { theme, toggleTheme };
}