Persistant Dark/Light mode.
This commit is contained in:
parent
54454bbb85
commit
2114c03c29
15
src/App.js
15
src/App.js
|
@ -23,7 +23,7 @@ function App() {
|
||||||
[tagsChecked, setTagsChecked] = useState(true),
|
[tagsChecked, setTagsChecked] = useState(true),
|
||||||
[sortBy, setSortBy] = useState('Default'),
|
[sortBy, setSortBy] = useState('Default'),
|
||||||
[loader, setLoader] = useState(false),
|
[loader, setLoader] = useState(false),
|
||||||
[lightMode, setLightMode] = useState(false);
|
[lightMode, setLightMode] = useState(localStorage.getItem('light-mode') === 'true');
|
||||||
|
|
||||||
function SetLoader(x) {
|
function SetLoader(x) {
|
||||||
setLoader(x)
|
setLoader(x)
|
||||||
|
@ -82,14 +82,27 @@ function App() {
|
||||||
setNumberOfResults(filteredData.length);
|
setNumberOfResults(filteredData.length);
|
||||||
}, [filteredData]);
|
}, [filteredData]);
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// const isLight = localStorage.getItem("light-mode");
|
||||||
|
|
||||||
|
// if (JSON.parse(isLight)) {
|
||||||
|
// setLightMode(true);
|
||||||
|
// } else {
|
||||||
|
// setLightMode(false);
|
||||||
|
// }
|
||||||
|
// }, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (lightMode) {
|
if (lightMode) {
|
||||||
document.body.classList.add("light");
|
document.body.classList.add("light");
|
||||||
} else {
|
} else {
|
||||||
document.body.classList.remove("light");
|
document.body.classList.remove("light");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localStorage.setItem('light-mode', lightMode);
|
||||||
}, [lightMode]);
|
}, [lightMode]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<div className='content'>
|
<div className='content'>
|
||||||
|
|
Ŝarĝante…
Reference in New Issue