fix: undefined document in ssr

This commit is contained in:
Sagnik Pradhan
2021-10-19 14:46:18 -04:00
committed by Jean-Philippe Sirois
parent b6b295fced
commit c81d9246c4
2 changed files with 7 additions and 3 deletions
+2
View File
@@ -14,6 +14,8 @@ const ThemeScript = () => {
else return "dark" else return "dark"
} }
if (typeof document === "undefined") return;
document.documentElement.style.setProperty( document.documentElement.style.setProperty(
"--initial-theme", "--initial-theme",
getInitialTheme() getInitialTheme()
+5 -3
View File
@@ -26,9 +26,11 @@ const ThemeProvider: FC<IScopedDownChildren> = ({ children }) => {
// App's current theme // App's current theme
const [theme, setTheme] = useState<ThemeType>( const [theme, setTheme] = useState<ThemeType>(
document.documentElement.style.getPropertyValue( typeof document !== "undefined"
"--initial-theme" ? (document.documentElement.style.getPropertyValue(
) as ThemeType "--initial-theme"
) as ThemeType)
: "dark"
) )
const themeObject = useMemo( const themeObject = useMemo(