import React, { useState, useEffect } from 'react'; import dateFormat from 'dateformat'; //DOCS: props.uri is the address of a live news-server const NewsFeed = props => { const [articles, setArticles] = useState([]); useEffect(async () => { const result = await fetch(props.uri, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, }); if (!result.ok) { const err = `${result.status}: ${await result.text()}`; console.log(err); alert(err); } else { setArticles(await result.json()); } }, []); return (

News Feed

{articles.map((article, index) => { return (

{article.title}

Written by {article.author}, { article.edits > 0 ? Last Updated {dateFormat(articles.updatedAt, 'fullDate')} ({`${article.edits} edit${article.edits > 1 ? 's': ''}`}) : Published {dateFormat(articles.createdAt, 'fullDate')} }

{article.body}

); })}
); }; export default NewsFeed;