A component library that helps you interact with the Spotify API
npm install react-spotify-apiA component library that helps you interact with the Spotify API





!Codecov



- Components for most of Spotify's data types that pass data through render props
- Hooks for most of Spotify's data
- [x] Pass Spotify data with render props
- [x] Use React.Context to pass the access token down the component tree
- [x] Hooks!
- [x] A demo page that uses this library - available here!
- [x] Load more data support (infinite scrolling) - current works for some of the data types
- [ ] TypeScript support!
- [ ] 100% code coverage
- [ ] Hooks for all data types from Spotify's API
- [ ] Hooks for using the Spotify Playback SDK
Before version 3.0.0 the parameters to props.children were passed in this order - data, loading, error. It is now passed as an object, so you would now use the Album component like this -
``jsx static`
{({ data }) => {
return <>>;
}}
As opposed to the previous versions where you would use the components like this -
`jsx static`
{(data, loading, error) => {
return <>>;
}}
This way you can choose which parameters you would like to have, and if you want just the error parameter you can omit the other two. This works well with the loadMoreData parameter, you don't need to write all 4 parameters if you just need some of them.
`bash`
npm install --save react-spotify-api
`bash`
yarn add react-spotify-api
in order to use the Spotify API you are required to send an access token (read more here)
with every single http request, but the SpotifyApiContext provider does that for you!
`js static`
import { SpotifyApiContext } from 'react-spotify-api';
`jsx static`
You can now use all components without worrying about getting your access token!
`jsx
import React, { Component } from 'react';
import { SpotifyApiContext, Artist } from 'react-spotify-api';
function Example(props) {
return (
{({ data, loading, error }) =>
data ? (
{data.name}
{data.genres.map(genre => (
))}
) : null
}
);
}
`
`jsx
import React from 'react';
import { useArtist } from 'react-spotify-api';
function ExampleHooks(props) {
const { data, loading, error } = useArtist(props.id);
return artist ? (
Data types
- data - Each component has a link to the Spotify API endpoint where you can see the data model for that specific data type
- loading - Boolean (_true_ when loading and _false_ when finished loading)
- error - _null_ when there are no errors but an _object_ when there are - usually containing the error object received by the
fetch api, so it looks something like: {status: 404, message: "Not Found"}`This project is licensed under the MIT License - see the LICENSE file for details
MIT © idanlo