@@ -4,6 +4,7 @@ import type { ComponentProps, FC } from 'react';
4
4
import type { IconBaseProps } from 'react-icons' ;
5
5
import { HiMoon , HiSun } from 'react-icons/hi' ;
6
6
import { twMerge } from 'tailwind-merge' ;
7
+ import { useIsMounted } from '~/src/hooks/use-is-mounted' ;
7
8
import { mergeDeep } from '../../helpers/merge-deep' ;
8
9
import { useThemeMode } from '../../hooks/use-theme-mode' ;
9
10
import { getTheme } from '../../theme-store' ;
@@ -31,6 +32,7 @@ export const DarkThemeToggle: FC<DarkThemeToggleProps> = ({
31
32
iconLight : IconLight = HiMoon ,
32
33
...props
33
34
} ) => {
35
+ const isMounted = useIsMounted ( ) ;
34
36
const { computedMode, toggleMode } = useThemeMode ( ) ;
35
37
36
38
const theme = mergeDeep ( getTheme ( ) . darkThemeToggle , customTheme ) ;
@@ -46,12 +48,12 @@ export const DarkThemeToggle: FC<DarkThemeToggleProps> = ({
46
48
>
47
49
< IconDark
48
50
aria-label = "Currently dark mode"
49
- data-active = { computedMode === 'dark' }
51
+ data-active = { isMounted && computedMode === 'dark' }
50
52
className = { twMerge ( theme . root . icon , 'hidden dark:block' ) }
51
53
/>
52
54
< IconLight
53
55
aria-label = "Currently light mode"
54
- data-active = { computedMode === 'light' }
56
+ data-active = { isMounted && computedMode === 'light' }
55
57
className = { twMerge ( theme . root . icon , 'dark:hidden' ) }
56
58
/>
57
59
</ button >
0 commit comments