File tree Expand file tree Collapse file tree
src/generators/web/ui/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,13 +28,9 @@ const applySystemTheme = () => applyTheme('system');
2828 */
2929export const useTheme = ( ) => {
3030 // 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- } ) ;
31+ const [ pref , setPref ] = useState ( ( ) =>
32+ SERVER ? 'system' : ( localStorage . getItem ( 'theme' ) ?? 'system' )
33+ ) ;
3834
3935 // Apply theme on every preference change, and if 'system',
4036 // also listen for OS-level color scheme changes.
@@ -53,7 +49,7 @@ export const useTheme = () => {
5349 /** Updates the preference in both React state and localStorage. */
5450 const setTheme = useCallback ( next => {
5551 setPref ( next ) ;
56- if ( typeof window !== 'undefined' ) {
52+ if ( CLIENT ) {
5753 localStorage . setItem ( 'theme' , next ) ;
5854 }
5955 } , [ ] ) ;
You can’t perform that action at this time.
0 commit comments