Last active
February 14, 2019 16:46
-
-
Save hamatoyogi/fdad4340be0b4e9c90dcd7728c399194 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
export default class Article extends Component { | |
// notice that it's an async function | |
static async getInitialProps () { | |
// fetch data on the server and parse it to JSON | |
const res = await | |
fetch('http://localhost:3000/wp-json/wp/v2/articles/1316999'); | |
const json = await res.json(); | |
// return data from the server so it can be consumed by our component | |
// all returned data from this method is added to out React.Component this.props | |
return { | |
articleContent: json.content.rendered, | |
} | |
} | |
render() { | |
const { articleContent } = this.props; | |
return ( | |
<Layout> | |
<ArticleHead/> | |
<div dangerouslySetInnerHTML={{ __html: articleContent }}/> | |
</Layout> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment