Using arrow function in React JS - Callback

When you need to perform setState in a callback function, for example call api and update the data as below

1
2
3
4
5
6
7
8
9
10
axios.get('http://yourdomain/api/get-data')
.then(function (response) {
// handle success
this.setState({
data: response.data
})
})
.catch(function (error) {
// handle error
})
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×