Created
June 30, 2016 18:42
-
-
Save vutran/23c4f90d070c13dee5e8f9df274e31d6 to your computer and use it in GitHub Desktop.
sample ghost component
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
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