Skip to content

Commit

Permalink
fix: NextJS errors on difference between server-render and client-ren…
Browse files Browse the repository at this point in the history
…der (#22)

This is because linkText is different on server (no "window") and
client. Fix that by using a React hook.
  • Loading branch information
TrueBrain authored Nov 24, 2023
1 parent 32482c1 commit b9ffc41
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/ShipFit/FitLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import { useEveShipFitLink } from "../EveShipFitLink";

import styles from "./ShipFit.module.css";

const useIsRemoteViewer = () => {
const [remote, setRemote] = React.useState(true);

React.useEffect(() => {
if (typeof window !== "undefined") {
setRemote(window.location.hostname !== "eveship.fit");
}
}, []);

return remote;
}

export const FitLink = () => {
const link = useEveShipFitLink();

/* Detect if the fit is loaded on https://eveship.fit */
const isEveShipFit = typeof window !== "undefined" && window.location.hostname === "eveship.fit";
const linkText = isEveShipFit ? "link to fit" : "open on eveship.fit";
const linkText = useIsRemoteViewer() ? "open on eveship.fit" : "link to fit";

return <div className={styles.fitlink}>
<svg viewBox="0 0 730 730" xmlns="http://www.w3.org/2000/svg">
Expand Down

0 comments on commit b9ffc41

Please sign in to comment.