Last active
December 29, 2017 00:25
-
-
Save astrotim/b4065c9055bb11c662f2b984ecc6bfe8 to your computer and use it in GitHub Desktop.
updated with Contentful API call
This file contains hidden or 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 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