-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuseSpotifyData.ts
More file actions
33 lines (30 loc) · 979 Bytes
/
Copy pathuseSpotifyData.ts
File metadata and controls
33 lines (30 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// File: hooks/useSpotifyData.ts
'use client'
import { useWebSocket } from '@/context/WebSocketContext'
import { useMemo } from 'react'
/**
* @description A hook to extract memoized Spotify data from the WebSocket context.
* This hook ensures that consumers only re-render when the specific spotifyData values change.
* @returns {object} An object containing the Spotify data.
*/
export const useSpotifyData = () => {
const { spotifyData } = useWebSocket()
const memoizedSpotifyData = useMemo(() => {
return {
trackName: spotifyData.trackName,
artist: spotifyData.artist,
isPlaying: spotifyData.isPlaying,
albumArtUrl: spotifyData.albumArtUrl,
durationMs: spotifyData.durationMs,
progressMs: spotifyData.progressMs,
}
}, [
spotifyData.trackName,
spotifyData.artist,
spotifyData.isPlaying,
spotifyData.albumArtUrl,
spotifyData.durationMs,
spotifyData.progressMs,
])
return memoizedSpotifyData
}