Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/SongCard.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import type { Song } from '../data/songs'
import { useLyrics } from '../hooks/useLyrics'

type SongCardProps = {
song: Song
}

export function SongCard({ song }: SongCardProps) {

const { data } = useLyrics(song.artist, song.title)

return (
<article>
<h2>{song.title}</h2>
<p>{song.artist}</p>
<p>{song.album}</p>

<div>
<p>Teksten vises her</p>
<p>{data?.lyrics}</p>
</div>

<div>
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/useLyrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useQuery } from "@tanstack/react-query";

export function useLyrics(artist: string, title: string) {

const url = `https://api.lyrics.ovh/v1/${encodeURIComponent(artist)}/${encodeURIComponent(title)}`

const { data, isLoading, error } = useQuery({
queryKey: ['lyrics', artist, title],
queryFn: () => fetch(url).then((res) => res.json())
})

return {data, isLoading, error}
}