summaryrefslogtreecommitdiff
path: root/hooks/use-meta-color.ts
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
committerjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
commit1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch)
tree8a5587f10ca55b162d7e3254cb088b323a34c41b /hooks/use-meta-color.ts
initial commit
Diffstat (limited to 'hooks/use-meta-color.ts')
-rw-r--r--hooks/use-meta-color.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/hooks/use-meta-color.ts b/hooks/use-meta-color.ts
new file mode 100644
index 00000000..65d33433
--- /dev/null
+++ b/hooks/use-meta-color.ts
@@ -0,0 +1,25 @@
+import * as React from "react"
+import { useTheme } from "next-themes"
+
+import { META_THEME_COLORS } from "@/config/site"
+
+export function useMetaColor() {
+ const { resolvedTheme } = useTheme()
+
+ const metaColor = React.useMemo(() => {
+ return resolvedTheme !== "dark"
+ ? META_THEME_COLORS.light
+ : META_THEME_COLORS.dark
+ }, [resolvedTheme])
+
+ const setMetaColor = React.useCallback((color: string) => {
+ document
+ .querySelector('meta[name="theme-color"]')
+ ?.setAttribute("content", color)
+ }, [])
+
+ return {
+ metaColor,
+ setMetaColor,
+ }
+} \ No newline at end of file