Skip to content
Advertisement

unable to update hooks variable when fetching multiple urls in react

I am trying to store data from the TMDB movie api using a custom react hook .

useFetch.js

JavaScript

When I console.log({promises}) I get this object where the 2 items are the movie types with 20 movies inside : enter image description here And then when I try to display the movies from the object above in another component :

MovieList.js

JavaScript

I get nothing no movies displayed . I would appreciate your help with this .

Advertisement

Answer

Await is not working as expected inside Array.map(). You should either use for loop or use Promise.all()

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement