We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 729901f commit 68bdbd3Copy full SHA for 68bdbd3
1 file changed
src/generators/web/ui/hooks/useTheme.mjs
@@ -29,6 +29,10 @@ const applySystemTheme = () => applyTheme('system');
29
export const useTheme = () => {
30
// Read stored preference once on mount; default to 'system'.
31
const [pref, setPref] = useState(() => {
32
+ if (typeof window === 'undefined') {
33
+ return 'system';
34
+ }
35
+
36
return localStorage.getItem('theme') || 'system';
37
});
38
@@ -49,7 +53,9 @@ export const useTheme = () => {
49
53
/** Updates the preference in both React state and localStorage. */
50
54
const setTheme = useCallback(next => {
51
55
setPref(next);
52
- localStorage.setItem('theme', next);
56
+ if (typeof window !== 'undefined') {
57
+ localStorage.setItem('theme', next);
58
59
}, []);
60
61
return [pref, setTheme];
0 commit comments