This commit is contained in:
Nino Chavez 2026-02-24 00:03:08 +00:00 committed by GitHub
commit ed9d8c6a09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

View File

@ -1,5 +1,6 @@
"use client";
import { useEffect, useState } from "react";
import { Button } from "./ui/button";
import { useTheme } from "next-themes";
import { cn } from "@/utils/ui";
@ -18,6 +19,25 @@ export function ThemeToggle({
onToggle,
}: ThemeToggleProps) {
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
// Prevent hydration mismatch by not rendering theme-dependent content until mounted
if (!mounted) {
return (
<Button
size="icon"
variant="ghost"
className={cn("size-8", className)}
>
<span className={cn("!size-[1.1rem]", iconClassName)} />
<span className="sr-only">Toggle theme</span>
</Button>
);
}
return (
<Button