Last active
August 5, 2019 15:50
-
-
Save jeffscottward/206a508ec378da3f1ad1b4c44d5fe86b to your computer and use it in GitHub Desktop.
Next.js Data querying example
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 React, { Component } from 'react' | |
const Index = () => ( | |
<div className="IndexPage"> | |
<label>{this.props.APIdata.key}</label> | |
<span>{this.props.APIdata.value}</span> | |
<style jsx>{` | |
.IndexPage { color: blue; } | |
`}</style> | |
</div> | |
) | |
Index.getInitialProps = () => { | |
// await response of fetch call | |
let response = await fetch('https://quantstamp.com/api/v1/JSONDATA') | |
// only proceed once promise is resolved | |
let APIdata = await response.json() | |
// only proceed once second promise is resolved | |
return { APIdata } | |
} | |
export default Index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment