"use client"; import { useTheme } from "next-themes"; import { ComponentProps, useSyncExternalStore } from "react"; import { Button } from "@/components/shadcn/button/button"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/shadcn/tooltip"; import { MoonFilledIcon, SunFilledIcon } from "./icons"; export type ThemeSwitchProps = ComponentProps<"button">; const emptySubscribe = () => () => {}; export function ThemeSwitch({ className, ...props }: ThemeSwitchProps) { const { theme, setTheme } = useTheme(); // Hydration-safe mounted check: false on the server, true after hydration const isHydrated = useSyncExternalStore( emptySubscribe, () => true, () => false, ); const isLightMode = theme === "light" || !isHydrated; return ( {isLightMode ? "Switch to Dark Mode" : "Switch to Light Mode"} ); }