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