datahandler

This commit is contained in:
skidoodle 2022-10-09 01:09:41 +02:00
parent 18242ba058
commit eb5487385e

View file

@ -12,18 +12,22 @@ import profilePic from "public/profile.webp";
import { useState } from "react"; import { useState } from "react";
export default function () { export default function () {
const [spotify, setSpotify] = useState<any>("nothing"); const [spotify, setSpotify] = useState<any>("");
useEffect(() => { const handleData = () => {
const interval = setInterval(() => {
fetch("/api/spotify") fetch("/api/spotify")
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .then((data) => setSpotify(data));
setSpotify(data); };
});
}, 9999);
return () => clearInterval(interval); useEffect(() => {
handleData();
return () => {
setInterval(() => {
handleData();
}, 3000);
};
}, []); }, []);
return ( return (
@ -61,7 +65,7 @@ export default function () {
<Link href={`${spotify.song.url}`}> <Link href={`${spotify.song.url}`}>
<a target="_blank" className="text-[#32a866]"> <a target="_blank" className="text-[#32a866]">
{" "} {" "}
{spotify.song.title || "nothing"} {spotify.song.title}
</a> </a>
</Link> </Link>
) : ( ) : (