please help :)
I'm doing simple Axios get request, in a "Component Did Mount". In a simple/basic react app. I'm trying to get FourSquare place data for London.
My function works, as I can console.log data. Here's my component did mount code:
// FOURSQUARE COMPONENT DID MOUNT
componentDidMount() {
console.log('COMPONENT DID MOUNT');
axios.get('https://api.foursquare.com/v2/venues/explore…')
.then(res => {
console.log('data', res.data.response.groups[0].items);
// console.log('data',res.data.response.groups[0].items[0].venue.name);
this.setState(
{ places: res.data.response.groups[0].items}
);
});
}
Please here the screenshot attached of console.log. https://i.imgur.com/DPPxwdW.png
However, I'm trying to map through the data, to get "venue.name" in the object array/res.data. But I keep getting the following error:
Cannot read property 'map' of undefined
Here is how I'm trying to map through the data....
const Loaders = ({places}) => {
return (
<section>
<div className="columns is-multiline">
{places.map((place, i) => <div className="column is-one-quarter" key={i}>
<ul>
<li>
<div className="card-image">
<figure className="image">
<h2 className="has-text-centered has-text-grey">title: {place.venue.name}</h2>
</figure>
</div>
</li>
</ul>
</div>)}
</div>
</section>
);
};
export default Loaders;