Question:
I am trying to fetch info from an endpoint and assign it to a local variable. The problem is that the info is fetched successfully and when I put console.log(resp.data) it is printed, so I assign it to the faculties, but in the following line faculties is an empty array. I tried async/await -> I defined showOptions function as async and awaited facultiesService.getAllFaculties(), but the problem was not solved and some other errors occured. How can I solve this issue?Answer:
You are using async/await in wrong way. They are meant for sequential code rather than callbacks. You should be doing something like this:If you have better answer, please add a comment about this, thank you!