this is my first time to develop a react application.
I will be using the get response of axios to populate a table. The outside var is declared and used outside the scope of the axios, and when I update that var inside the scope of axios, it does not update the var data outside, as per checking in debug.
Is there a way to use the get response of axios outside/ in global scope?
Thank you very much for your help.
//rows is declared outside the scope
let rows = [];
axios
.get(`url here`)
.then(res => {
for (let i = 0; i < res.data.length; i++) {
//rows.push not reflecting on the react application (inside scope of res)
rows.push(res.data[i]);
}
});
//rows.push reflecting on the react application (outside scope of res)
rows.push({
test: 5.7
});