useEffect(() => {
_getMovies();
// eslint-disable-next-line
},[]);
function _renderMovies() {
return movies.map(movie => {
console.log(movie)
return <Movie title={movie.title} poster={movie.large_cover_image} key={movie.id} />
});
}
async function _getMovies(){
const movies = await _callApi();
setMovies(movies);
}
function _callApi() {
return fetch("https://yts.lt/api/v2/list_movies.json?sort_by=rating")
.then(response => response.json())
.then(json => json.data.movies)
.catch(err => console.log(err))
}
return (
<div className="App">
{movies ? _renderMovies() : 'Loading'}
</div>
);
}