Skip to content

Commit 2bc3a7b

Browse files
committed
chore: store dark in localStorage only after user interaction
1 parent 9045feb commit 2bc3a7b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

playground/app.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export const App = (): JSX.Element => {
102102
createEffect(() => {
103103
const action = dark() ? 'add' : 'remove';
104104
document.body.classList[action]('dark');
105-
localStorage.setItem('dark', String(dark()));
106105
});
107106

108107
const header = !noHeader;
@@ -137,7 +136,11 @@ export const App = (): JSX.Element => {
137136
children={
138137
<Header
139138
dark={dark()}
140-
toggleDark={() => setDark(!dark())}
139+
toggleDark={() => {
140+
const toggledValue = !dark();
141+
setDark(toggledValue);
142+
localStorage.setItem('dark', String(toggledValue));
143+
}}
141144
isHorizontal={isHorizontal}
142145
tabs={tabs()}
143146
setTabs={setTabs}

0 commit comments

Comments
 (0)