I was trying to fetch the news api but I kept on geeting this errors "" TypeError: Cannot read properties of undefined (reading 'map') "" is there any syntax or I need to add something
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>
)
}
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/aRjcpSZ
Comments
Post a Comment