My page brake when i make an request to an API, i receive the contents and it prints on the console.
function getFilms() {
fetch('https://ghibliapi.herokuapp.com/films')
.then((response) => response.json())
.then((data) => {
console.log(data);
return data;
});
}
export default getFilms;
I've tried to use a implicit return and return outside of the '.them' without success.
I was receiving undefined because the the caller didn't received the return of the API. Solved by returing the fetch.
function getFilms() { return fetch('https://ghibliapi.herokuapp.com/films').then((response) => response.json()).then((data) => { console.log(data); }); } export default getFilms;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.