Skip to content

Commit

Permalink
Attempt #2 to fix build - gatsbyjs/gatsby#309 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Aug 27, 2022
1 parent 0dbc1ed commit 8b06859
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/theme-selector.tsx
Expand Up @@ -3,7 +3,7 @@ import React from "react";
const windowGlobal = (typeof window !== 'undefined' && window) as Window;

export default function ThemeSelector() {
const userPreference = windowGlobal.localStorage.getItem("theme");
const userPreference = windowGlobal == null ? null : windowGlobal.localStorage.getItem("theme");

const [selectedTheme, setSelectedTheme] = React.useState(
userPreference || "light"
Expand All @@ -30,7 +30,9 @@ export default function ThemeSelector() {
{themes.map((theme) => (
<button className="btn btn-default" onClick={() => {
setThemeCssVariables(theme);
windowGlobal.localStorage.setItem("theme", theme);
if (windowGlobal) {
windowGlobal.localStorage.setItem("theme", theme);
}
setSelectedTheme(theme);
}}>
{theme}
Expand Down

0 comments on commit 8b06859

Please sign in to comment.