From 4947052dcf547c5c0f2fb7f42f7556e467d8695d Mon Sep 17 00:00:00 2001 From: arch0Xd <71967828+arch0Xd@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:06:01 +0200 Subject: [PATCH] szerveroldaliba --- pages/index.tsx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 336057b..d6c14b8 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,7 +1,6 @@ import Image from "next/image"; import Link from "next/link"; -import React from "react"; -import useSWR from "swr"; +import React, { useEffect } from "react"; import FadeIn from "react-fade-in"; import { socials } from "components/data/socials"; @@ -10,14 +9,14 @@ import { Toaster } from "react-hot-toast"; import { FaSpotify } from "react-icons/fa"; import profilePic from "../public/profile.webp"; +import { GetServerSideProps } from "next"; +import { useRouter } from "next/router"; -const fetcher = (url: RequestInfo) => fetch(url).then((r) => r.json()); +export default function ({ spotify }: any) { + const { asPath, replace } = useRouter() + + useEffect(() => { replace(asPath) }, [spotify]) -export default function () { - const { data: spotify } = useSWR("/api/spotify", fetcher, { - refreshInterval: 1000, - }); - if (!spotify) return; return (
@@ -79,3 +78,14 @@ export default function () { ); } + +export const getServerSideProps: GetServerSideProps = async () => { + const { HOST } = process.env + + const res = await fetch(`${HOST}/api/spotify`) + const data = await res.json() + + return { + props: { spotify: data } + } +} \ No newline at end of file