From 2114c03c290f1eed16bebdc64e33699a0582353b Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 7 Jun 2022 19:13:49 +0430 Subject: [PATCH] Persistant Dark/Light mode. --- src/App.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 9f54883..c4c7fdb 100644 --- a/src/App.js +++ b/src/App.js @@ -23,7 +23,7 @@ function App() { [tagsChecked, setTagsChecked] = useState(true), [sortBy, setSortBy] = useState('Default'), [loader, setLoader] = useState(false), - [lightMode, setLightMode] = useState(false); + [lightMode, setLightMode] = useState(localStorage.getItem('light-mode') === 'true'); function SetLoader(x) { setLoader(x) @@ -82,13 +82,26 @@ function App() { setNumberOfResults(filteredData.length); }, [filteredData]); + // useEffect(() => { + // const isLight = localStorage.getItem("light-mode"); + + // if (JSON.parse(isLight)) { + // setLightMode(true); + // } else { + // setLightMode(false); + // } + // }, []); + useEffect(() => { if (lightMode) { document.body.classList.add("light"); } else { document.body.classList.remove("light"); } + + localStorage.setItem('light-mode', lightMode); }, [lightMode]); + return (