我试图获取新闻api,但我一直遇到这个错误 "" TypeError:不能读取未定义的属性(读取'map') "" 是否有任何语法或我需要添加一些东西?
import React, { Component } from 'react'
import NewsItem from './NewsItem'
export default class News extends Component {
constructor(){
super();
this.state={
article : this.article
}
}
async componentDidMount(){
let urll = "https://newsapi.org/v2/top-headlines?
country=in&apiKey=6aeca0faebbd45c1a1ec3c463f703ebb";
let data = await fetch(urll);
console.log(data)
let parseData = await data.json() ;
console.log(parseData);
this.setState({article : parseData.articles});
}
render() {
return (
<div className='newcontainer my-5'>
<h1 className='mainheading' >PAHADI PRESS BREAKING NEWS</h1>
{this.state.article.map((e)=>{
return <div key={e.url} >
<NewsItem title={e.title} decription={e.description} imageUrl={e.urlToImage}
newsUrl={e.url}
newsauthor={e.author}/>
</div>
})
}
</div>
)
}
}