I am trying to store the API response in the async/await functions into the response global variable which will be later accessed by App() but I am being prompted with the error shown below the code.
async function getAllTutors() {
try{
const response = await axios.get('API...');
console.log("getAllTutors(): " + JSON.stringify(response.data.body));
return response;
}catch(error) {
return [];
}
}
var response = null;
(async () => {
console.log("Retrieving Tutors");
response = await getAllTutors();
console.log("response (caller) = " + JSON.stringify(response.data.body))
})();
function App() {
...
console.log("HERE: " + JSON.stringify(response.data.body));
const [ data, setTutors ] = useState(employees);
...
I tried logging the values while in both functions and it does seem to output the desired JSON object but, App() still shows response variable to be undefined. I even tried to change App() to be async/await but I am being lead into other errors.