Skip to content

Commit 8e5f7fe

Browse files
committed
refactor: use radix solution
1 parent 82bdcd7 commit 8e5f7fe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
'use client';
22

3-
import { updateThemeAppearanceClass } from '@radix-ui/themes';
3+
import { updateThemeAppearanceClass, useThemeContext } from '@radix-ui/themes';
44

55
const THEME_KEY = 'fuel-ui-theme';
66

77
export function useTheme() {
8+
const { appearance: theme, onAppearanceChange } = useThemeContext();
9+
810
function toggleTheme() {
911
const current = localStorage.getItem(THEME_KEY);
1012
const next = current === 'light' ? 'dark' : 'light';
1113
updateThemeAppearanceClass(next);
14+
onAppearanceChange(next);
1215
localStorage.setItem(THEME_KEY, next);
1316
}
1417

15-
return { theme: localStorage.getItem(THEME_KEY) || 'dark', toggleTheme };
18+
return { theme, toggleTheme };
1619
}

0 commit comments

Comments
 (0)