Created
March 4, 2018 14:37
-
-
Save JonatanSalas/d1d944aaa1fed63d3fe80c13f4a19586 to your computer and use it in GitHub Desktop.
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 characters
| 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> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment