From 25e9c10e26a369fc04afe58f33f3a465133e644a Mon Sep 17 00:00:00 2001 From: developomp Date: Mon, 17 May 2021 16:18:18 +0900 Subject: [PATCH] code quality improvement --- source/src/App.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/src/App.tsx b/source/src/App.tsx index 2604837..b6f7a1d 100644 --- a/source/src/App.tsx +++ b/source/src/App.tsx @@ -125,14 +125,15 @@ blockquote { ` function App() { - const [usingTheme, _setTheme] = useState(() => { + const [currentTheme, _setTheme] = useState(() => { const savedTheme = storage.getItem("theme") return savedTheme ? JSON.parse(savedTheme) : { mode: "dark" } }) + // save theme when theme is changed useEffect(() => { - storage.setItem("theme", JSON.stringify(usingTheme)) - }, [usingTheme]) + storage.setItem("theme", JSON.stringify(currentTheme)) + }, [currentTheme]) const [isLoading, setLoading] = useState(true) @@ -154,7 +155,7 @@ function App() { _setTheme(theme), // make setTheme function available in other components }} @@ -167,7 +168,7 @@ function App() {