Created
March 4, 2018 14:37
-
-
Save JonatanSalas/d1d944aaa1fed63d3fe80c13f4a19586 to your computer and use it in GitHub Desktop.
Revisions
-
Jonatan E. Salas created this gist
Mar 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ import React from 'react'; import withCache from './withCache'; import newsFecher from './newsFetcher'; import Placeholder from './Placeholder'; @withCache export default class News extends React.Component { static getDerivedStateFromProps = (nextProps, nextState) => ({ news: newsFetcher(nextProps.cache) }); render() { const { news } = this.state; return ( <Placeholder delayMs={1000} fallback={<h1>Loading..</h1>}> {news.map(this.renderNewsItem)} </Placeholder> ) } renderNewsItem = (nws, idx) => ( <div key={`nws.${idx}-${nws.id}`}> <h2>{nws.title}</h2> <p>{nws.body}</p> </div> ); }