+ 2

How access data outside of axios.post in ReactJS?

The response data is not accessable outside the axios request body axios.post(url) .then(res => { //data is accessible here }); //I want to access here

11th Mar 2020, 8:38 PM
Ajay Agrawal
Ajay Agrawal - avatar
3 Antworten
+ 3
You can store data in global variable.
11th Mar 2020, 8:45 PM
A͢J
A͢J - avatar
+ 3
Somewhere else in the program, you declare (in the global scope) var result; Then, in the.then(), you do: result = res; (If you want to store res into result)
11th Mar 2020, 10:27 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Idea of global variable doesn't work, I tried a lot
12th Mar 2020, 3:16 AM
Ajay Agrawal
Ajay Agrawal - avatar