Created
March 7, 2019 02:40
-
-
Save levlaz/0818f4995b768eb59effb340cc41e1b6 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 Layout from '../components/MyLayout.js' | |
import fetch from 'isomorphic-unfetch' | |
const Index = (props) => ( | |
<Layout> | |
<h1>Features</h1> | |
<ul> | |
{props.featureKeys.map((key, index) => ( | |
<li key={key}> | |
{key} is {props.features[key]} | |
</li> | |
))} | |
</ul> | |
</Layout> | |
) | |
Index.getInitialProps = async function ({ req }) { | |
let features = {}; | |
let featureKeys = []; | |
if (req) { | |
features = req.features; | |
for (let p in features) { | |
if (features.hasOwnProperty(p)) { | |
featureKeys.push(p); | |
} | |
} | |
} else { | |
const res = await fetch('/api/features') | |
features = await res.json() | |
for (let p in features) { | |
if (features.hasOwnProperty(p)) { | |
featureKeys.push(p); | |
} | |
} | |
} | |
return { | |
features: features, | |
featureKeys: featureKeys | |
} | |
}; | |
export default Index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment