I want to fetch all the movies data in API when my movie app starts
I tried using fetch function I used in search box ,to see If the data is correctly getting fetched I am tying to see it on ‘console.log’, but it throws an error
(intermediate value) is not iterable
TypeError: (intermediate value) is not iterable
Here is what I tried:
const fetchMovies = async () => {
const [ res ] = await fetch(`${API_URL}`);
const dat = await res.json();
console.log(dat);
}
useEffect(() => {
fetchMovies()
}, []);
2
Answers
The response from
await fetch
is not an array but rather an object so you got the error.Remove the square bracket – [] and you will be fine.
You can read more about fetch here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
you can simply resolve the Promise using
.then