I want to add genre to my Movie Search app's carousel using map function. I have two json files one of them is an array of movie data as objects having a key as genre_ids eg:
genre_ids: 0: 16 1: 28 2: 12 3: 35 4: 10751 5: 14
and other contains an array of objects specifying the name of the genre with a unique key. eg:
{ "genres": [ { "id": 10759, "name": "Action & Adventure" } ] }
The Json files:
- Movie data: https://api.themoviedb.org/3/trending/all/day?api_key=921345714956c7d9c3db36ac3f20ee09
- Genre: https://api.themoviedb.org/3/genre/movie/list?api_key=921345714956c7d9c3db36ac3f20ee09&language=en-US
I tried mapping the json with movie data first. Then while mapping the genre i checked if the id of the genre matches with that of the id of the movie data element. Then I returned the name of that particular genre. But it is returning the names of all the genre present in the genre json.
My code:
{
trend.map((e, i) => {
return (
<div className="carousel-item" key={i}>
<img
src={`${img}${e.backdrop_path}`}
className="d-block carimage" alt="..." />
<div className="carousel-caption d-none d-md-block">
<div className='caro-discription'>
<button className='trailer-main-button'>More Info!!</button>
<h1>{e.title?e.title:e.name}</h1>
<h3>Rating: {e.vote_average}/10</h3>
</div>
<div className='genre-list'>
{genre.map((a,b)=>{
return(
<h3 className='genre-list-item' key={b}>{a.id=e.genre_ids? a.name: null}</h3>
)
})}
</div>
</div>
</div>
)
})
}