mirror of
https://github.com/skidoodle/albert.lol.git
synced 2025-02-15 06:09:15 +01:00
datahandler
This commit is contained in:
parent
18242ba058
commit
eb5487385e
1 changed files with 14 additions and 10 deletions
|
@ -12,18 +12,22 @@ import profilePic from "public/profile.webp";
|
|||
import { useState } from "react";
|
||||
|
||||
export default function () {
|
||||
const [spotify, setSpotify] = useState<any>("nothing");
|
||||
const [spotify, setSpotify] = useState<any>("");
|
||||
|
||||
const handleData = () => {
|
||||
fetch("/api/spotify")
|
||||
.then((res) => res.json())
|
||||
.then((data) => setSpotify(data));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
fetch("/api/spotify")
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setSpotify(data);
|
||||
});
|
||||
}, 9999);
|
||||
handleData();
|
||||
|
||||
return () => clearInterval(interval);
|
||||
return () => {
|
||||
setInterval(() => {
|
||||
handleData();
|
||||
}, 3000);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
@ -61,7 +65,7 @@ export default function () {
|
|||
<Link href={`${spotify.song.url}`}>
|
||||
<a target="_blank" className="text-[#32a866]">
|
||||
{" "}
|
||||
{spotify.song.title || "nothing"}
|
||||
{spotify.song.title}
|
||||
</a>
|
||||
</Link>
|
||||
) : (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue