spotify fetch update

This commit is contained in:
skidoodle 2022-10-09 00:12:41 +02:00
parent fc6e12bc55
commit 026d96d3f4

View file

@ -11,13 +11,22 @@ import { FaSpotify } from "react-icons/fa";
import profilePic from "../public/profile.webp"; import profilePic from "../public/profile.webp";
import { GetServerSideProps } from "next"; import { GetServerSideProps } from "next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useState } from "react";
export default function ({ spotify }: any) { export default function () {
const { asPath, replace } = useRouter(); const [spotify, setSpotify] = useState("");
useEffect(() => { useEffect(() => {
replace(asPath); const interval = setInterval(() => {
}, [spotify]); fetch("/api/spotify")
.then((res) => res.json())
.then((data) => {
setSpotify(data);
});
}, 9999);
return () => clearInterval(interval);
}, []);
return ( return (
<FadeIn> <FadeIn>
@ -80,14 +89,3 @@ export default function ({ spotify }: any) {
</FadeIn> </FadeIn>
); );
} }
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 },
};
};