updated doc handling hydration mismatch error (#1449)

Co-authored-by: btsb78 <gaurav.pandey@kratikal.com>
This commit is contained in:
Gaurav Pandey 2023-08-21 02:12:01 +05:30 committed by GitHub
parent 691f380dff
commit ea2868e58e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,10 +96,18 @@ Add the theme switcher to your app.
"use client";
import {useTheme} from "next-themes";
import { useEffect, useState } from "react";
export const ThemeSwitcher = () => {
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}