ReactJS_VideoGuides icon indicating copy to clipboard operation
ReactJS_VideoGuides copied to clipboard

Unhandled Rejection (TypeError): Cannot read property 'items' of undefined

Open kevinlaiGH opened this issue 7 years ago • 2 comments

24 | }) 25 | .then(response => response.json()) 26 | .then(json => { 27 | const artist = json.artists.items[0]; 🚀 28 | this.setState({ artist }); 29 | 30 | FETCH_URL = ${ALBUM_URL}${artist.id}/top-tracks?country=US&;

In line 27, I kept encountering the same error, what is 0 referring to?

kevinlaiGH avatar May 19 '18 11:05 kevinlaiGH

you need to send your request like this fetch(FETCH_URL,{ method: 'GET', headers: { 'Authorization': 'Bearer ' + accessToken }, mode: 'cors', cache: 'default' }).then.... Because you are not getting your token send in the request, and you are not getting any object back, thats why you get an undefined object. Also if your token expired you need to generate a new one.

Rene-Torres avatar Jun 30 '18 03:06 Rene-Torres

access Token is not defined error and header is not defined error

Hamza156-rgb avatar Jan 15 '21 13:01 Hamza156-rgb