Skip to content

Instantly share code, notes, and snippets.

@dharavp
Created November 27, 2018 11:32
Show Gist options
  • Save dharavp/d24e9d925b032a46cc33ab45863a8baf to your computer and use it in GitHub Desktop.
Save dharavp/d24e9d925b032a46cc33ab45863a8baf to your computer and use it in GitHub Desktop.
fetchUser(page) {
//stackexchange User API url
const url = `https://api.stackexchange.com/2.2/users?page=${page}&order=desc&sort=reputation&site=stackoverflow`;
this.setState({ loading: true })
axios.get(url)
.then(res => {
let listData = this.state.data;
let data = listData.concat(res.data.items) . //concate list with response
this.setState({ loading: false, data: data })
})
.catch(error => {
this.setState({ loading: false, error: 'Something just went wrong' })
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment