Support SSR

This commit is contained in:
Ariful Alam
2022-03-25 18:47:28 +06:00
parent 5058711985
commit c6066fd038
2 changed files with 4 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ const ThemeChanger = ({ theme, setTheme, loading }) => {
const changeTheme = (e, selectedTheme) => { const changeTheme = (e, selectedTheme) => {
e.preventDefault(); e.preventDefault();
document.querySelector('html').setAttribute('data-theme', selectedTheme); document.querySelector('html').setAttribute('data-theme', selectedTheme);
typeof window !== 'undefined' &&
localStorage.setItem('gitprofile-theme', selectedTheme); localStorage.setItem('gitprofile-theme', selectedTheme);
setTheme(selectedTheme); setTheme(selectedTheme);

View File

@@ -8,6 +8,7 @@ export const getInitialTheme = () => {
} }
if ( if (
typeof window !== 'undefined' &&
!(localStorage.getItem('gitprofile-theme') === null) && !(localStorage.getItem('gitprofile-theme') === null) &&
config.themeConfig.themes.includes(localStorage.getItem('gitprofile-theme')) config.themeConfig.themes.includes(localStorage.getItem('gitprofile-theme'))
) { ) {