Skip to content

Instantly share code, notes, and snippets.

@SamWSoftware
Created December 11, 2017 12:52
Show Gist options
  • Save SamWSoftware/a04e5ba555e6cbdf40821cbf6d3c96b2 to your computer and use it in GitHub Desktop.
Save SamWSoftware/a04e5ba555e6cbdf40821cbf6d3c96b2 to your computer and use it in GitHub Desktop.
export default class Blog extends Component {
constructor(props) {
super(props);
this.state = {
posts: []
};
}
componentDidMount() {
axios
.get(
"http://public-api.wordpress.com/rest/v1/sites/samwcoding.wordpress.com/posts"
)
.then(res => {
this.setState({ posts: res.data.posts });
console.log(this.state.posts);
})
.catch(error => console.log(error));
}
render() {
return (
<div className="blog">
<h1 className="sectionTitle">Articles</h1>
{this.state.posts.map(post => <ArticlePreview post={post} />)}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment