Switch theme btn
This commit is contained in:
@@ -13,9 +13,6 @@ const Background = ({ children, className }) => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
setTheme(localStorage.getItem("theme") ? localStorage.getItem("theme") : "light");
|
||||
|
||||
circlesRef.current.forEach((circle) => {
|
||||
if (circle) {
|
||||
const { x, y } = getRandomTranslation();
|
||||
@@ -25,7 +22,22 @@ const Background = ({ children, className }) => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
useEffect(() => {
|
||||
const updateTheme = () => {
|
||||
setTheme(localStorage.getItem("theme") || "light");
|
||||
};
|
||||
|
||||
updateTheme(); // Initial load
|
||||
|
||||
window.addEventListener("theme-changed", updateTheme);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("theme-changed", updateTheme);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
return (
|
||||
<div className={`${styles.backgroundContainer} ${className || ''} ${theme === "light" ? styles.backgroundLight : styles.backgroundDark}`}>
|
||||
<div
|
||||
ref={(el) => (circlesRef.current[0] = el)}
|
||||
|
||||
Reference in New Issue
Block a user