Created
December 28, 2017 23:33
-
-
Save astrotim/9ea6ddbab10bbf0af9071a28c0e535b7 to your computer and use it in GitHub Desktop.
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 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() { | |
- return <p>Home</p>; | |
+ if (!this.state.posts.length) return <p>No posts found.</p>; | |
+ | |
+ return this.state.posts.map(post => { | |
+ console.log(post); | |
+ return <p>Post</p>; | |
+ }); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment