First commit
This commit is contained in:
22
hooks/useTheme.ts
Normal file
22
hooks/useTheme.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTheme as useNextTheme } from "next-themes";
|
||||
|
||||
export function useTheme() {
|
||||
const { theme, resolvedTheme, setTheme } = useNextTheme();
|
||||
const [mounted] = useState(true);
|
||||
|
||||
const currentTheme = resolvedTheme ?? theme ?? "light";
|
||||
|
||||
const toggleTheme = () => {
|
||||
setTheme(currentTheme === "dark" ? "light" : "dark");
|
||||
};
|
||||
|
||||
return {
|
||||
theme: currentTheme,
|
||||
setTheme,
|
||||
toggleTheme,
|
||||
mounted,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user