Skip to content

Commit

Permalink
fix(website): force render on client-side (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
gillisandrew authored and sekwah41 committed Feb 26, 2022
1 parent 530bf4e commit fb9f111
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
59 changes: 33 additions & 26 deletions website/src/components/SVG.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import PomatezSVG from "../assets/icons/pomatez.svg";
import DownloadSVG from "../assets/icons/download.svg";
import SunnySVG from "../assets/icons/sunny.svg";
Expand All @@ -10,38 +10,45 @@ import LinuxSVG from "../assets/icons/linux.svg";
import SnapStoreSVG from "../assets/icons/snap-store.svg";
import TuxSVG from "../assets/icons/tux.svg";
import ArrowBackSVG from "../assets/icons/arrow-back.svg";
import { useIsBrowser } from "../hooks/useIsBrowser";

type Props = {
name?: string;
};

export const SVG: React.FC<Props> = ({ name }) => {
switch (name) {
case "pomatez":
return <PomatezSVG />;
case "download":
return <DownloadSVG />;
case "sunny":
return <SunnySVG />;
case "moon":
return <MoonSVG />;
case "github":
return <GithubSVG />;
case "windows":
return <WindowSVG />;
case "apple":
return <AppleSVG />;
case "linux":
return <LinuxSVG />;
case "snap-store":
return <SnapStoreSVG />;
case "tux":
return <TuxSVG />;
case "arrow-back":
return <ArrowBackSVG />;
default:
return <PomatezSVG />;
const isBrowser = useIsBrowser();

if (isBrowser) {
switch (name) {
case "pomatez":
return <PomatezSVG />;
case "download":
return <DownloadSVG />;
case "sunny":
return <SunnySVG />;
case "moon":
return <MoonSVG />;
case "github":
return <GithubSVG />;
case "windows":
return <WindowSVG />;
case "apple":
return <AppleSVG />;
case "linux":
return <LinuxSVG />;
case "snap-store":
return <SnapStoreSVG />;
case "tux":
return <TuxSVG />;
case "arrow-back":
return <ArrowBackSVG />;
default:
return <PomatezSVG />;
}
}

return null;
};

export default React.memo(SVG);
12 changes: 12 additions & 0 deletions website/src/hooks/useIsBrowser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect, useState } from "react";

export const useIsBrowser = () => {
const [isBrowser, setIsBrowser] = useState(false);

useEffect(() => {
setIsBrowser(true);
return () => setIsBrowser(false);
}, []);

return isBrowser;
};

0 comments on commit fb9f111

Please sign in to comment.