I have a function that fetches from an API. Then I'd like to assign a variable to a data point from the API.
Then at the end return this value. I'm using this function to run a loop that creates a chart of currency conversions.
This is the function:
getConversion(amount, fromCurrency, toCurrency) {
let converted; //want to return this variable at the end
fetch(`${this.state.rootUrl}/latest?amount=${amount}&from=${fromCurrency}&to=${toCurrency}`)
.then(response => {
return response.json();
})
.then(data => {
converted = data.rates[toCurrency] //assign the conversion amount
})
r