Skip to content

Commit

Permalink
fix: theme switch ssr issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sapkra committed Jun 30, 2024
1 parent b29d689 commit 5ea59f6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/theme-switch/ThemeSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ import { useTheme } from 'next-themes';
import { IconMoon, IconSun } from '@tabler/icons-react';
import { Button } from '../base';
import { ButtonProps } from '@nextui-org/react';
import { useEffect, useState } from 'react';

/**
* Primary UI component for selecting a color
*/

export interface ThemeSwitchProps extends ButtonProps {
}
export interface ThemeSwitchProps extends ButtonProps {}

export const ThemeSwitch: React.FC<ThemeSwitchProps> = (props) => {
const { theme, setTheme } = useTheme()
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();

useEffect(() => {
setMounted(true);
}, []);

if(!mounted) return null;

return (
<Button isIconOnly size="sm" onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')} {...props}>
{theme === 'light' ? <IconSun size={18} /> : <IconMoon size={18} />}
</Button>
)
);
};

0 comments on commit 5ea59f6

Please sign in to comment.