Skip to content

Instantly share code, notes, and snippets.

@vutran
Created June 30, 2016 18:42
Show Gist options
  • Save vutran/23c4f90d070c13dee5e8f9df274e31d6 to your computer and use it in GitHub Desktop.
Save vutran/23c4f90d070c13dee5e8f9df274e31d6 to your computer and use it in GitHub Desktop.
sample ghost component
import React, { Component } from 'react';
import got from 'got';
class PostEntry extends Component {
constructor(props) {
super(props);
this.state = {
post: false,
};
}
componentDidMount() {
const { postId } = this.props;
// load from API
got(`http://api.ghost.org/posts/${postId}`).then(resp => {
// set the API response to the state
this.setState({
post: resp.body,
});
});
}
render() {
// retrieve the post from the state
const { post } = this.state;
return (
<div>
<h1>{post.title</h1>
<div>{post.html}</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment