mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
theme-toggle (#52)
* default to system preferred theme * theme svg in footer * accounted for undefined window
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||
|
||||
function useDarkMode(): [string, Dispatch<SetStateAction<string>>] {
|
||||
const prefersDarkMode =
|
||||
typeof window !== "undefined" &&
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
const [theme, setTheme] = useState(
|
||||
typeof window !== "undefined" ? localStorage.theme : "dark"
|
||||
typeof window !== "undefined"
|
||||
? localStorage.theme || (prefersDarkMode ? "dark" : "light")
|
||||
: "dark"
|
||||
);
|
||||
|
||||
const colorTheme = theme === "dark" ? "light" : "dark";
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user