Overview
TheuseAddToQueue hook provides a convenient way to add Spotify tracks to the user’s playback queue. It handles the Spotify SDK integration and error handling internally.
Signature
Parameters
This hook takes no parameters.Return Value
Returns an async function that accepts aSpotifyTrack object and adds it to the playback queue.
Function signature:
Function Parameters
The Spotify track object to add to the queue. Must include a
uri property.Usage Example
Fromsrc/components/ContextMenu.tsx:15:
How It Works
The hook internally:- Accesses the Spotify SDK from the
SpotifyContext - Returns an async function that:
- Validates that both the track and SDK are available
- Calls
sdk.player.addItemToPlaybackQueue()with the track’s URI - Returns early if either the track or SDK is not available
Dependencies
This hook requires:- The
SpotifyContextto be available in the component tree - A valid Spotify SDK instance with player permissions
Type Information
The hook expects aSpotifyTrack object which should include: