Skip to content

Commit 72810dd

Browse files
committed
feat: update theme-color meta tag when theme is updated
1 parent 9b38001 commit 72810dd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/components/theme-switch.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { IconMoon, IconSun } from '@tabler/icons-react'
22
import { useTheme } from './theme-provider'
33
import { Button } from './custom/button'
4+
import { useEffect } from 'react'
45

56
export default function ThemeSwitch() {
67
const { theme, setTheme } = useTheme()
8+
9+
/* Update theme-color meta tag
10+
* when theme is updated */
11+
useEffect(() => {
12+
const themeColor = theme === 'dark' ? '#020817' : '#fff'
13+
const metaThemeColor = document.querySelector("meta[name='theme-color']")
14+
metaThemeColor && metaThemeColor.setAttribute('content', themeColor)
15+
}, [theme])
16+
717
return (
818
<Button
919
size='icon'

0 commit comments

Comments
 (0)