Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Created June 1, 2018 08:55
Show Gist options
  • Select an option

  • Save PrimeTimeTran/9e0929166e48aa80a1cc7e35da026fd8 to your computer and use it in GitHub Desktop.

Select an option

Save PrimeTimeTran/9e0929166e48aa80a1cc7e35da026fd8 to your computer and use it in GitHub Desktop.
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)
})
}
}
@wmira
Copy link

wmira commented Jun 1, 2018

Do something like request.then( api => api.get ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment