Skip to content

Instantly share code, notes, and snippets.

@astrotim
Last active December 29, 2017 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrotim/b4065c9055bb11c662f2b984ecc6bfe8 to your computer and use it in GitHub Desktop.
Save astrotim/b4065c9055bb11c662f2b984ecc6bfe8 to your computer and use it in GitHub Desktop.
updated with Contentful API call
import React from 'react';
import { createClient } from 'contentful';
class Home extends React.Component {
state = {
posts: []
};
componentWillMount() {
const client = createClient({
space: process.env.REACT_APP_SPACE_ID,
accessToken: process.env.REACT_APP_ACCESS_TOKEN
});
client
.getEntries({})
.then(response => {
this.setState({
posts: response.items
});
})
.catch(console.error);
}
render() {
if (!this.state.posts.length) return <p>No posts found.</p>;
return this.state.posts.map(post => {
console.log(post);
return <p>Post</p>;
});
}
}
export default Home;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment