Is there any method to change the value of a global variable using async function then use that variable globally?

36 Views Asked by At

I got a async function used to call to api and a global variable named dataOut

let dataOut
let fetchData = async () => {
    let raw = await fetch('https://api.themoviedb.org/3/movie/upcoming?api_key=1b8102c1e52c1cbbf4197b9c7c0f28ad');
    dataIn = await raw.json()
    return dataIn
}

Is there any way that I can assign the "dataOut" to the data that is fetched in the fetchData, or use the data in the fetchData globally. For example:

<p>{dataOut.key}</p>
0

There are 0 best solutions below