0.2.2 • Published 5 years ago

use-spotify-web-playback-sdk v0.2.2

Weekly downloads
63
License
MIT
Repository
github
Last release
5 years ago

use-spotify-web-playback-sdk

React hook for interacting with the Spotify Web Playback SDK.

Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.

You'll need to install react, react-dom, etc at ^16.7.0-alpha.0

Install

yarn add use-spotify-web-playback-sdk

Usage

import useSpotifyWebPlaybackSdk from "use-spotify-web-playback-sdk";

function MyComponent() {
  const {
    Script: WebPlaybackSdkScript,
    deviceId,
    connect: connectWebPlaybackSdk,
    player, // https://developer.spotify.com/documentation/web-playback-sdk/reference/#api-spotify-player
    isReady,
  } = useSpotifyWebPlaybackSdk({
    name: "My Spotify Player", // Device that shows up in the spotify devices list
    getOAuthToken: () => Promise.resolve(sessionStorage.getItem("accessToken")), // Wherever you get your access token from
    onPlayerStateChanged: (playerState) => {
      console.log('player state changed:', playerState);
    }
  });

  React.useEffect(
    () => {
      if (isReady) {
        connect();
      }
    },
    [isReady],
  );

  // value == ...
  return (
    <React.Suspense fallback={<div>Loading...</div>}>
    <WebPlaybackSdkScript>
      <div>Any children</div>
    </WebPlaybackSdkScript>
    </React.Suspense>
  );
}

Also check out the TypeScript definitions for all options that can be passed to the hook

Help

Check out the Spotify Playback SDK docs for reference or feel free to open an issue.

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.10-0

5 years ago

0.0.9-0

5 years ago

0.0.8-0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago