Trying to understand the promise function but struggling with returning the value. Any help would be appreciated.
static getTrailer(movieId) {
return fetch(`http://api.themoviedb.org/3/movie/${movieId}?api_key=###&append_to_response=videos`)
.then(response => {
return response.json();
})
.then(responseJson => {
if (responseJson.videos.results[0]) {
Promise.resolve(responseJson.videos.results[0].key)
.then(result => {
console.log(result);
return result;
});
} else {
return Promise.reject(`Trailer is not found`);
}
});
}
Tried to retrieve the result here:
<p>${DataSource.getTrailer(this._movie.id).then(resultKey => {console.log("data is: " + resultKey)})}</p>
However, the resultKey always returns as undefined. Can someone guide me on how to resolve this issue?