-
-
Save amandeepmittal/60b762dc26bd2d155a4cc3316ba09b01 to your computer and use it in GitHub Desktop.
This file contains 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 fetch from 'isomorphic-fetch'; | |
class Index extends React.Component { | |
static async getInitialProps() { | |
let stories; | |
try { | |
const response = await fetch( | |
'https://node-hnapi.herokuapp.com/news?page=1' | |
); | |
stories = await response.json(); | |
} catch (err) { | |
console.log(err); | |
stories = []; | |
} | |
return { stories }; | |
} | |
render() { | |
const { stories } = this.props; | |
return ( | |
<div> | |
<h1>Hacker News Clone</h1> | |
<div> | |
{stories.map(story => ( | |
<h3 key={story.id}>{story.title}</h3> | |
))} | |
</div> | |
</div> | |
); | |
} | |
} | |
export default Index; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment