Skip to content

Instantly share code, notes, and snippets.

@astrotim
Created December 29, 2017 00:56
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/ea270cb613025fa541b1deb70e78aeab to your computer and use it in GitHub Desktop.
Save astrotim/ea270cb613025fa541b1deb70e78aeab to your computer and use it in GitHub Desktop.
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