Skip to content

Commit c7cc4b2

Browse files
fix: use resolvedTheme instead of theme for toggle and revert to node version 18
1 parent e42b684 commit c7cc4b2

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

.github/workflows/ci-cd-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ permissions:
3030
deployments: write
3131

3232
env:
33-
NODE_VERSION: '20.x'
33+
NODE_VERSION: '18.x'
3434
CACHE_NAME: 'node-modules-v1'
3535

3636
# Cancel previous runs if a new commit is pushed

components/theme-toggle.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,21 @@ import * as React from "react";
44
import { Moon, Sun } from "lucide-react";
55
import { useTheme } from "next-themes";
66

7-
/**
8-
* Theme toggle component that switches between light and dark modes.
9-
* Displays sun icon in light mode and moon icon in dark mode with smooth transitions.
10-
*
11-
* @component
12-
* @returns {JSX.Element | null} The theme toggle button or null during SSR
13-
*/
147
export function ThemeToggle() {
158
const [mounted, setMounted] = React.useState(false);
16-
const { theme, setTheme } = useTheme();
9+
const { resolvedTheme, setTheme } = useTheme(); // Changed: use resolvedTheme
1710

1811
React.useEffect(() => {
1912
setMounted(true);
2013
}, []);
2114

22-
// Prevent hydration mismatch by not rendering on server
2315
if (!mounted) {
2416
return null;
2517
}
2618

2719
return (
2820
<button
29-
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
21+
onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")} // Changed: use resolvedTheme
3022
className="relative inline-flex h-10 w-10 items-center justify-center rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors"
3123
aria-label="Toggle theme"
3224
>
@@ -35,4 +27,4 @@ export function ThemeToggle() {
3527
<span className="sr-only">Toggle theme</span>
3628
</button>
3729
);
38-
}
30+
}

0 commit comments

Comments
 (0)