When you need to perform setState in a callback function, for example call api and update the data as below
1 | axios.get('http://yourdomain/api/get-data') |
Using the usual callback function like this you will get an error that this.setState is not a function
To fix this you usually create a variable outside the callback function to store this pointer as below
1 | const that = this |
However, you can also handle this problem by using the arrow function
1 | axios.get('http://yourdomain/api/get-data') |