Something went wrong. Try again.
version 2 of my website
Something went wrong. Try again.
591 B · 26 lines
TypeScript
123456789101112131415161718192021222324252627import type { TrackResponse } from "@/types/lastfm";import { useEffect, useState } from "react";
export function useLastFm() { const [track, setTrack] = useState<TrackResponse>(); const [loading, setLoading] = useState(true); const [error, setError] = useState(null);
useEffect(() => { fetch('/api/lastfm/recentTracks') .then(res => res.json()) .then(data => { setTrack(data); setLoading(false); }) .catch(err => { setError(err.message); setLoading(false); }) }, [])
return { track, loading, error }}