diff options
| author | joonhoekim <26rote@gmail.com> | 2025-03-25 15:55:45 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-03-25 15:55:45 +0900 |
| commit | 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch) | |
| tree | 8a5587f10ca55b162d7e3254cb088b323a34c41b /hooks/use-meta-color.ts | |
initial commit
Diffstat (limited to 'hooks/use-meta-color.ts')
| -rw-r--r-- | hooks/use-meta-color.ts | 25 |
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 |
