https://github.com/idanlo/react-spotify-api
A React component library that makes it easier to interact with the Spotify API
https://github.com/idanlo/react-spotify-api
react react-spotify spotify-api spotify-library spotify-web-api
Last synced: about 2 months ago
JSON representation
A React component library that makes it easier to interact with the Spotify API
- Host: GitHub
- URL: https://github.com/idanlo/react-spotify-api
- Owner: idanlo
- License: mit
- Created: 2018-09-26T20:02:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-23T21:35:12.000Z (over 2 years ago)
- Last Synced: 2025-04-07T09:04:37.153Z (2 months ago)
- Topics: react, react-spotify, spotify-api, spotify-library, spotify-web-api
- Language: JavaScript
- Homepage: https://idanlo.github.io/react-spotify-api/
- Size: 7.75 MB
- Stars: 279
- Watchers: 7
- Forks: 16
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-spotify-api
A component library that helps you interact with the Spotify API
# [Demo](https://react-spotify.netlify.com/browse/featured)
[](https://www.npmjs.com/package/react-spotify-api)
[](https://travis-ci.com/idanlo/react-spotify-api)
[](https://david-dm.org/idanlo/react-spotify-api)
[](https://david-dm.org/idanlo/react-spotify-api?type=dev)
[](https://david-dm.org/idanlo/react-spotify-api?type=peer)

[](https://www.npmjs.com/package/react-spotify-api)
[](https://opensource.org/licenses/MIT)
[](http://makeapullrequest.com)# [Documentation](https://idanlo.github.io/react-spotify-api/)
# Features
- Components for most of Spotify's data types that pass data through render props
- Hooks for most of Spotify's data# Roadmap
- [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!](https://react-spotify.netlify.com/browse/featured)
- [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](https://developer.spotify.com/documentation/web-playback-sdk)# Version 3.0.0 Breaking Change
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.
# Installing
## with npm
```bash
npm install --save react-spotify-api
```## with yarn
```bash
yarn add react-spotify-api
```## Wrapping your app with a Provider
in order to use the Spotify API you are required to send an access token ([read more here](https://developer.spotify.com/documentation/general/guides/authorization-guide/))
with every single http request, but the `SpotifyApiContext` provider does that for you!### Import
```js static
import { SpotifyApiContext } from 'react-spotify-api';
```### Wrap your app with it (all react-spotify-api components must have a SpotifyApiContext.Provider parent)
```jsx static
```
You can now use all components without worrying about getting your access token!
## Component usage
```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 => (
- {genre}
))}
) : null
}
);
}
```## Hooks usage _(assuming the ExampleHooks component is wrapped with the SpotifyApiContext.Provider)_
```jsx
import React from 'react';import { useArtist } from 'react-spotify-api';
function ExampleHooks(props) {
const { data, loading, error } = useArtist(props.id);return artist ? (
{artist.name}
{artist.genres.map(genre => (
- {genre}
))}
) : null;
}
```## 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"}`## License
This project is licensed under the MIT License - see the LICENSE file for details
MIT © [idanlo](https://github.com/idanlo)