Jamming Feature Request - Playlist Fetch

I am trying to retrieve Spotify Playlists.
I have the API up and running fine. But When I try to load it to state I get this error -

TypeError: util_Spotify__WEBPACK_IMPORTED_MODULE_6_.Spotify.getPlaylistList() is undefined

Here is the code-
In Spotify.js -

getPlaylistList() {
        accessToken = Spotify.getAccessToken();
        .then(userId => {
            return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
                headers: {
                    Authorization: `Bearer ${accessToken}`
        .then(response => {
            const jsonResponse = response.json();
            return jsonResponse;
        .then(jsonResponse => {
            if (!jsonResponse.items) {
                return [];

            return jsonResponse.items.map(playlist => ({
                id: playlist.id,
                name: playlist.name

In App.js -

  getPlaylistList() {
    Spotify.getPlaylistList().then(playlist => {
        playlistList: playlist


  componentDidMount() {
    window.addEventListener('load', (event) => {
      this.getPlaylistList().then(playlistList => {
        this.setState({playlistList: playlistList});

If I do a simple Spotify.getPlaylist() call, then console.log shows a good return. So it has something to do with setting the state… Any ideas? Loosing my mind!!

I might add that “this” is also bound to the new method.

Further investigation has found that it is not setState( ) that breaks the code, but simply attaching a .then()… Why this is happening is well beyond my scope of understanding and I’m struggling to find similar cases on the web.

Problem solved. Although not understood.
Despite the error message and how it worked under certain conditions. The overall fault was in the way I was utilising my getUserId() method.