Skip to content

Commit 096cad2

Browse files
author
Joel Klabo
committed
fix: ensure theme toggle uses current theme value
Previously the theme toggle callback referenced nextTheme which was computed at render time. Now it computes the new theme value inline to avoid any potential stale closure issues. Fixes #292
1 parent 6723808 commit 096cad2

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

apps/social/src/screens/SettingsScreen.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ export function SettingsScreen({
6868
const [profileError, setProfileError] = useState<string | null>(null);
6969

7070
const handleThemeToggle = useCallback(() => {
71-
setTheme(nextTheme);
71+
const newTheme = theme === 'dark' ? 'light' : 'dark';
72+
setTheme(newTheme);
7273
toast({
73-
message: `Theme set to ${nextTheme}.`,
74+
message: `Theme set to ${newTheme}.`,
7475
tone: 'success'
7576
});
76-
}, [nextTheme, setTheme, toast]);
77+
}, [theme, setTheme, toast]);
7778

7879
const handleBrandPresetSelect = useCallback(
7980
(nextBrandPreset: NsBrandPreset) => {

0 commit comments

Comments
 (0)