&&
?{ news && news.map(newsItem =>....
class News extends React.Component {
state = {};
componentDidMount() {
const url =
"https://newsapi.org...";
fetch(url)
.then(responce => responce.json())
.then(m => this.setState({ news: [...m.articles] }));
}
render() {
const { news } = this.state;
return (
<Wrapper>
<div style={{ width: "100%" }}>
<Typography variant="h2" component="h1" gutterBottom>
Новости
</Typography>
</div>
{ news &&
news.map(newsItem => (
<Card
title={newsItem.title}
key={
new Date(newsItem.publishedAt).getTime() - Math.random() * 25
}
urlToImage={newsItem.urlToImage}
description={newsItem.description}
/>
))}
</Wrapper>
);
}
}
export default News;
news.map(newsItem => (
<Card
title={newsItem.title}
key={
new Date(newsItem.publishedAt).getTime() - Math.random() * 25
}
urlToImage={newsItem.urlToImage}
description={newsItem.description}
/>
))
news.length !== 0 && <List />
{
news ? <List data={news} /> : null
}
news && <List data={news} />