titles/components/ThemeSwitcher.tsx
ChrQR 6dd60de8f4
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m7s
Set up next-theme and dark mode with toggle example
2024-05-17 11:16:20 +02:00

26 lines
600 B
TypeScript

// app/components/ThemeSwitcher.tsx
"use client";
import { Button } from "@nextui-org/button";
import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
export function ThemeSwitcher() {
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) return null;
return (
<div>
The current theme is: {theme}
<Button onClick={() => setTheme("light")}>Light Mode</Button>
<Button onClick={() => setTheme("dark")}>Dark Mode</Button>
</div>
);
}