I'm trying to define a prop on a react component using a method. The method is working fine and I can return a correct result to the console. However when I inspect my component with react browser extension I can see no props are assigned to the component, nor can I use them within the component.
class NowPlaying extends Component {
state = {
genres: []
};
componentDidMount() {
// Fetch Genre Data
axios.get(`${base_url}genre/movie/list?api_key=${api_key}`)
.then(res => this.setState({ genres: res.data.genres }))
}
getGenreTitles = (genreIds, genres) => {
genreIds.map(genreId => {
const filteredGenres = genres.filter(genre => genre.id === genreId);
const { name } = filteredGenres[0];
return name;
})
};
render() {
return this.props.movies.map((movie) => (
<MovieItem
key={movie.id}
movie={movie}
genres={this.getGenreTitles(movie.genre_ids, this.state.genres)}
/>
));
}
}
Expectation is that the name is returned as a prop which can then be used in the movieitem component.