File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
components/NavbarComponents Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 22
33import { Moon , Sun } from "lucide-react" ;
44import { useTheme } from "next-themes" ;
5- import { useEffect } from "react" ;
5+ import { useEffect , useState } from "react" ;
66
77export default function ThemeToggle ( ) {
88 const { theme, setTheme } = useTheme ( ) ;
9+ const [ mounted , setMounted ] = useState ( false ) ;
10+
11+ useEffect ( ( ) => {
12+ setMounted ( true ) ;
13+ } , [ ] ) ;
914
1015 useEffect ( ( ) => {
1116 const handleKeyPress = ( e : KeyboardEvent ) => {
@@ -19,6 +24,8 @@ export default function ThemeToggle() {
1924 return ( ) => window . removeEventListener ( "keydown" , handleKeyPress ) ;
2025 } , [ theme , setTheme ] ) ;
2126
27+ if ( ! mounted ) return null ;
28+
2229 return (
2330 < button
2431 onClick = { ( ) => setTheme ( theme === "dark" ? "light" : "dark" ) }
You can’t perform that action at this time.
0 commit comments