Skip to content

Commit

Permalink
Attempt #3 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 8b06859 commit afcd4fd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 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 == null ? null : windowGlobal.localStorage.getItem("theme");
const userPreference = windowGlobal?.localStorage == null ? null : windowGlobal.localStorage.getItem("theme");

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

0 comments on commit afcd4fd

Please sign in to comment.