Created
June 1, 2018 08:55
-
-
Save PrimeTimeTran/9e0929166e48aa80a1cc7e35da026fd8 to your computer and use it in GitHub Desktop.
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 client from '../utils/client'; | |
| export default class Main extends React.Component { | |
| state = { posts: [] } | |
| componentWillMount() { | |
| const request = client(); | |
| request.get(`${API_ROOT}posts`).then(response => { | |
| return response.data | |
| }).then(data => { | |
| this.setState({ posts: data }) | |
| }).catch(error => { | |
| console.log('Error:', error) | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do something like request.then( api => api.get ...)