We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f118530 commit a6bda54Copy full SHA for a6bda54
1 file changed
src/context/ThemeContext.jsx
@@ -20,6 +20,17 @@ export function ThemeProvider({ children }) {
20
localStorage.setItem(STORAGE_KEY, theme);
21
}, [theme]);
22
23
+ // Sync across tabs
24
+ useEffect(() => {
25
+ const handler = (e) => {
26
+ if (e.key === STORAGE_KEY && e.newValue) {
27
+ setTheme(e.newValue);
28
+ }
29
+ };
30
+ window.addEventListener('storage', handler);
31
+ return () => window.removeEventListener('storage', handler);
32
+ }, []);
33
+
34
const toggleTheme = () =>
35
setTheme((t) => (t === 'dark' ? 'light' : 'dark'));
36
0 commit comments