Protect against potentially data not having items
parent
c801a1d63e
commit
7d5dd7f1a8
|
@ -3,34 +3,36 @@ import React, {PropTypes} from 'react'
|
|||
import moment from 'moment'
|
||||
|
||||
const JSONFeedReader = ({data}) =>
|
||||
data
|
||||
data && data.items
|
||||
? <div className="newsfeed">
|
||||
{data.items.map(
|
||||
({
|
||||
id,
|
||||
date_published,
|
||||
url,
|
||||
title,
|
||||
author: {name},
|
||||
image,
|
||||
content_text: contentText,
|
||||
}) =>
|
||||
<div key={id} className="newsfeed--post">
|
||||
<div className="newsfeed--date">
|
||||
{`${moment(date_published).format('MMM DD')}`}
|
||||
</div>
|
||||
<div className="newsfeed--post-title">
|
||||
<a href={url} target="_blank">
|
||||
<h6>{title}</h6>
|
||||
</a>
|
||||
<span>by {name}</span>
|
||||
</div>
|
||||
<div className="newsfeed--content">
|
||||
{image ? <img src={image} /> : null}
|
||||
<p>{contentText}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data.items
|
||||
? data.items.map(
|
||||
({
|
||||
id,
|
||||
date_published,
|
||||
url,
|
||||
title,
|
||||
author: {name},
|
||||
image,
|
||||
content_text: contentText,
|
||||
}) =>
|
||||
<div key={id} className="newsfeed--post">
|
||||
<div className="newsfeed--date">
|
||||
{`${moment(date_published).format('MMM DD')}`}
|
||||
</div>
|
||||
<div className="newsfeed--post-title">
|
||||
<a href={url} target="_blank">
|
||||
<h6>{title}</h6>
|
||||
</a>
|
||||
<span>by {name}</span>
|
||||
</div>
|
||||
<div className="newsfeed--content">
|
||||
{image ? <img src={image} /> : null}
|
||||
<p>{contentText}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
: null}
|
||||
</div>
|
||||
: null
|
||||
|
||||
|
|
Loading…
Reference in New Issue