Skip to content

Instantly share code, notes, and snippets.

@astrotim astrotim/Post.js
Created Dec 29, 2017

Embed
What would you like to do?
retrieve entry data per post id
import React from 'react';
import { createClient } from 'contentful';
class Post extends React.Component {
constructor(props) {
super(props);
this.state = {
data: null
};
}
componentWillMount() {
const client = createClient({
space: process.env.REACT_APP_SPACE_ID,
accessToken: process.env.REACT_APP_ACCESS_TOKEN
});
client
.getEntry(this.props.match.params.id)
.then(response => {
this.setState({
data: response.fields
});
})
.catch(console.error);
}
render() {
console.log(this.state.data);
return <p>Post</p>;
}
}
export default Post;
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.