Skip to content

Instantly share code, notes, and snippets.

@hamatoyogi
Last active February 14, 2019 16:46
Show Gist options
  • Save hamatoyogi/fdad4340be0b4e9c90dcd7728c399194 to your computer and use it in GitHub Desktop.
Save hamatoyogi/fdad4340be0b4e9c90dcd7728c399194 to your computer and use it in GitHub Desktop.
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