Skip to content

Commit b1c4a74

Browse files
authored
feat: Persistent theme preference (#110)
* feat: Persistent theme preference * feat: Persistent theme
1 parent e3e0024 commit b1c4a74

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/docs/src/App.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ const App = () => {
3434
const [menuVisible, setMenuVisibility] = React.useState(false)
3535
const [locationKey, setLocationKey] = React.useState()
3636

37-
const [theme, setTheme] = React.useState('light')
37+
const defaultTheme = window.localStorage.getItem('theme') || 'light'
38+
const [theme, setTheme] = React.useState(defaultTheme)
3839

3940
document.querySelector('#favicon').href = `favicon-${theme}.png`
4041

42+
React.useEffect(() => {
43+
window.localStorage.setItem("theme", theme);
44+
},[theme])
45+
4146
React.useEffect(() => {
4247
setMenuVisibility(false)
4348
}, [locationKey])

0 commit comments

Comments
 (0)