Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.