Skip to content

Commit

Permalink
ThemeToggle refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Fermatka committed Apr 23, 2024
1 parent 53d3039 commit 032acab
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions algrtm/src/components/shared/ThemeToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import React, { useEffect, useState } from "react";
import Image from "next/image";

const ThemeToggle = () => {
const isClient = typeof window !== "undefined"; // Sprawdzamy, czy kod jest wykonywany po stronie klienta
const isClient = typeof window !== "undefined";
const [darkMode, setDarkMode] = useState(() => {
if (isClient) {
const theme = localStorage.getItem("theme");
return theme === "dark";
}
return false; // Domyślnie ustawiamy na false, jeśli kod jest wykonywany na serwerze
return false;
});

useEffect(() => {
if (isClient) {
// Sprawdzamy, czy kod jest wykonywany po stronie klienta
if (darkMode) {
document.documentElement.classList.add("dark");
localStorage.setItem("theme", "dark");
Expand Down

0 comments on commit 032acab

Please sign in to comment.