Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.