From f9323fbee8c4efc1477272fe5553ba5523ae7af3 Mon Sep 17 00:00:00 2001 From: SWASTI SUNDAR PRADHAN Date: Fri, 1 Sep 2023 00:24:49 +0530 Subject: [PATCH] Resolved Bug: Ensured Persistent Dark Mode State via Local Storage, Preventing Unintended Reversion to Default --- client/src/context/ThemeContext.jsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/src/context/ThemeContext.jsx b/client/src/context/ThemeContext.jsx index 9836cef1..b8a0a51a 100644 --- a/client/src/context/ThemeContext.jsx +++ b/client/src/context/ThemeContext.jsx @@ -20,6 +20,15 @@ const ThemeContextProvider = ({ children }) => { useEffect(() => { const currentHour = new Date().getHours(); setDarkTheme(currentHour >= 20 || currentHour <= 8 ? true : false); + localStorage.setItem( + 'darkTheme', + currentHour >= 20 || currentHour <= 8 ? 'true' : 'false', + ); + if (localStorage.getItem('darkTheme') === 'true') { + setDarkTheme(true); + } else if (localStorage.getItem('darkTheme') === 'false') { + setDarkTheme(false); + } }, [setDarkTheme]); return (