Next.js Discord

Discord Forum

Hydration Error

Unanswered
WiperR posted this in #help-forum
Open in Discord
supressHydrationWarning doesn't work on button as well as icon svgs.

What is alternate way to fix?

"use client";

import { useTheme } from "next-themes";
import { Button } from "./ui/button";
import { MoonIcon, SunIcon } from "lucide-react";

export function ThemeSwitch() {
  const { theme, setTheme } = useTheme();
  return (
    <Button
      variant="outline"
      size="icon"
      onClick={() => setTheme(theme == "dark" ? "light" : "dark")}
    >
      {theme == "dark" ? <SunIcon /> : <MoonIcon />}
    </Button>
  );
}

3 Replies