0

My goal is to access the API data from a fetch, and use it outside the function it was called in.

Here is an example of what I am trying to do. If I can never use the data from an async function outside of the function, does that mean that I can only use the data inside getWeatherData if I write more code inside getWeatherData? I plan to make other API calls, and I imagine that continuously nesting async functions to access data is not the right way to go about this.

Advice on how to resolve this is greatly appreciated!

Promise pending when expected javascript object

I have tried the fix from this question How can I return the fetch API results from a function?, and tried returning data without JSON.stringify or JSON.parse as well as adding await to those steps.

Haj
  • 1
  • 1
    *How to access async fetched API data syncronously* - you can't – Jaromanda X Nov 05 '22 at 00:48
  • why do you want it synchronously? that promise could easily take 200ms.. this means the browser tab hanging for that long, OR `let weather_today=await getWeatherData()` should work – The Bomb Squad Nov 05 '22 at 00:49

0 Answers0