I'm trying to get my code to display my spotify playlists when I press "My Playlists". Here is the error I recieve and I believe it's because the map function I provide is not an array.
Uncaught TypeError: this.state.myPlaylists.playlists.map is not a function
Here is my code.
getMyPlaylists(){
spotifyApi.getUserPlaylists()
.then((response) => {
this.setState({
myPlaylists: { playlists: response.items }
});
})
}
Here is my render loop function using map
{ this.state.loggedIn &&
<Button color="primary" variant="contained" onClick={() => this.getMyPlaylists()}>
My Playlists </Button> }
<div>
{this.state.myPlaylists.playlists.map((playlist) => {
return (
<div>
{playlist.name}
</div>
)
})}
</div>
How can I resolve this issue? Thanks stackoverflow community.