I need help with object iteration, usually I can just loop through an array but I haven't dealt with a single object before.
In my class based component I have this
this.state = {
itemDetails: []
};
axios.get(`${ROOT_URL}/${itemId}?${API_KEY}`).then(res => {
console.log(res.data);
this.setState({ itemDetails: res.data })
});
This returns JSON data that looks like
And I have an functional component looks like this
const MovieDetails = (props) => {
const arrayofKey = Object.keys(props.itemDetails).map((r) => {
<li
key={r.id} >
<a href='#t' className='rating'><i className='fas fa-star fa-fw' />{r.vote_average}</a>
<img src={`https://image.tmdb.org/t/p/w185/${r.poster_path}`} alt={r.title} className='search-results-poster' />
<a href='#t' className='search-results-name'>{r.name}</a>
<a href='#t' className='search-results-title'>{r.title}</a>
</li>
})
return <ul className='search-results'>{arrayofKey}</ul>
}
the error i'm currently getting is:
Expected an assignment or function call and instead saw an expression. (no-unused-expressions)
I just want to React to render the data I need, name, title etc