diff --git a/components/ui/SpotifyPlayer.tsx b/components/ui/SpotifyPlayer.tsx index 63b69f5..2f0e83c 100644 --- a/components/ui/SpotifyPlayer.tsx +++ b/components/ui/SpotifyPlayer.tsx @@ -1,11 +1,11 @@ 'use client' -import useSWR from 'swr' +import useSWR, {useSWRConfig} from 'swr' import fetcher from '@/lib/fetcher' import Image from 'next/image' import Link from 'next/link' import clsx from 'clsx' -import {useEffect, ReactElement, ElementType} from 'react' +import {ElementType, ReactElement, useEffect} from 'react' import {animate} from 'motion' type Status = { @@ -110,8 +110,11 @@ type PlayerStateResponse = { } function usePlayerState(path: string) { + const {mutate} = useSWRConfig() const {data, error, isLoading} = useSWR(`/api/spotify/${path}`, fetcher) as PlayerStateResponse + mutate(`/api/spotify/${path}`, data).then(r => r) + return { song: data, isLoading,