feat: removed useEffect in toggling theme

This commit is contained in:
Peter Carl Pardo committed 2024-12-18 18:57:38 +08:00
1 parent acefedd6e7
commit 7c5c3507d8
2 files changed
+12 -16

No files matched your search

+5 -9
View File
@@ -9,14 +9,13 @@
* Apache License: https://www.apache.org/licenses/LICENSE-2.0
*/
import React, { useEffect } from "react";
import { IconButton } from "@mui/material";
import SunAndMoonIcon from "./SunAndMoonIcon";
import "./index.css";
import { useDispatch, useSelector } from "react-redux";
import { setMode } from "../../Features/UI/uiSlice";
import "./index.css";
const ThemeSwitch = () => {
const ThemeSwitch = ({ width = 48, height = 48 }) => {
const mode = useSelector((state) => state.ui.mode);
const dispatch = useDispatch();
@@ -24,20 +23,17 @@ const ThemeSwitch = () => {
dispatch(setMode(mode === "light" ? "dark" : "light"));
};
useEffect(() => {
document.body.setAttribute("data-theme", mode);
}, [mode]);
return (
<IconButton
id="theme-toggle"
title="Toggles light & dark"
className={`theme-${mode}`}
aria-label="auto"
aria-live="polite"
onClick={toggleTheme}
sx={{
width: 48,
height: 48,
width,
height,
display: "flex",
alignItems: "center",
justifyContent: "center",