Skip to content

Commit

Permalink
Prevent previews from rendering on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantbh committed Dec 13, 2023
1 parent 2c5e10f commit eb14393
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/components/LoaderWithFacts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react';
import { ScatterBoxLoader } from 'react-awesome-loaders';
import { randInt } from '@/utils/number';
import { useIsClient } from 'usehooks-ts';

const openSourceStats = [
"Did you know: Rust has been the consistently most loved language in the last 3 years of StackOverflow's dev survey",
Expand Down Expand Up @@ -29,12 +30,9 @@ export const LoaderWithFacts = () => {
};
}, [currentIndex]);

const [isClient, setIsClient] = useState(false);
const isClient = useIsClient();

useEffect(() => {
setIsClient(true);

if (!window) return;
setCurrentText(openSourceStats[currentIndex]);
}, [currentIndex]);

Expand Down
5 changes: 5 additions & 0 deletions src/pages/previews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import React from 'react';
import { CARD_HEIGHT, CARD_WIDTH } from '../constants/general';
import Image from 'next/image';
import { ShareButton } from '@/components/ShareButton';
import { useIsClient } from 'usehooks-ts';

const Previews = () => {
const isClient = useIsClient();

const links = [
`/api/preview/intro`,
`/api/preview/timebased/allday`,
Expand All @@ -20,6 +23,8 @@ const Previews = () => {
`/api/preview/oss`
];

if (!isClient) return;

return (
<div className="flex flex-col bg-white text-black">
<a
Expand Down

0 comments on commit eb14393

Please sign in to comment.