Skip to content

Commit ef05929

Browse files
postpone swatch class attachment
1 parent fa49216 commit ef05929

File tree

1 file changed

+6
-4
lines changed
  • packages/devextreme-cli/src/templates/nextjs/application/src

1 file changed

+6
-4
lines changed

packages/devextreme-cli/src/templates/nextjs/application/src/theme.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client'
2-
import React, { useCallback, useMemo, useState } from 'react';
2+
import React, { useCallback, useMemo, useState, useLayoutEffect } from 'react';
33

44
const themes = ['light', 'dark'];
55
const themeClassNamePrefix = 'dx-swatch-';
@@ -44,9 +44,11 @@ export function useThemeContext() {
4444
return currentTheme === 'dark';
4545
}, []);
4646

47-
if (typeof window !== 'undefined' && !document.body.className.includes(themeClassNamePrefix)) {
48-
document.body.classList.add(themeClassNamePrefix + theme);
49-
}
47+
useLayoutEffect(() => {
48+
if (typeof window !== 'undefined' && !document.body.className.includes(themeClassNamePrefix)) {
49+
document.body.classList.add(themeClassNamePrefix + theme);
50+
}
51+
}, []);
5052

5153
return useMemo(()=> ({ theme, switchTheme, isDark }), [theme, switchTheme, isDark]);
5254
}

0 commit comments

Comments
 (0)