feat(theme) add ThemeSwitcher.tsx

This commit is contained in:
lumither committed 2024-04-24 21:13:40 +08:00
1 parent 0f415e7bf7
commit 83365be90b
7 files changed
+102 -32

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
'use client';
import React, { useEffect, useState } from 'react';
import { useTheme } from 'next-themes';
import { Button } from '@nextui-org/react';
function ThemeSwitcher() {
const [ mounted, setMounted ] = useState(false);
const { theme, setTheme, themes } = useTheme();
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}
return (
<div>
<Button onClick={ () => {
setTheme('light');
} }>Light Mode</Button>
<Button onClick={ () => {
setTheme('dark');
} }>Dark Mode</Button>
</div>
);
}
export default ThemeSwitcher;