From 026d96d3f40ad20f745518a11d213f3a9e7c2c23 Mon Sep 17 00:00:00 2001 From: skidoodle Date: Sun, 9 Oct 2022 00:12:41 +0200 Subject: [PATCH] spotify fetch update --- pages/index.tsx | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 56479af..62cce40 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -11,13 +11,22 @@ import { FaSpotify } from "react-icons/fa"; import profilePic from "../public/profile.webp"; import { GetServerSideProps } from "next"; import { useRouter } from "next/router"; +import { useState } from "react"; -export default function ({ spotify }: any) { - const { asPath, replace } = useRouter(); +export default function () { + const [spotify, setSpotify] = useState(""); useEffect(() => { - replace(asPath); - }, [spotify]); + const interval = setInterval(() => { + fetch("/api/spotify") + .then((res) => res.json()) + .then((data) => { + setSpotify(data); + }); + }, 9999); + + return () => clearInterval(interval); + }, []); return ( @@ -80,14 +89,3 @@ export default function ({ spotify }: any) { ); } - -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 }, - }; -};