constructor(props){
super(props);
this.state = {
posts: [],
}
}
componentWillMount() {
fetch("https://newsapi.org/v2/top-headlines?country=us&apiKey=${API_KEY}")
.then(res => res.json())
.then(data => this.setState({posts:data}));
}
render() {
return (
<div>
<ul>
{ this.state.posts.map(post => <li key={post.id}>{post.title}</li>) }
</ul>
</div>
)
}
I'm trying to map the title of this news object but whenever i try to do that I get this error: TypeError: this.state.posts.map is not a function. This is the picture of the object from data : https://i.stack.imgur.com/3fnlg.png