r/learnreactjs • u/DrakeJohnsonPHD • Mar 25 '22
API fetches go stale
I've built two functioning API get apps. One for weather that changes className with temperature of get. Another app does currency conversions by fetching the API. Now the API fails to update after initial call, and only updates occasionally, but I can't find a way to make the API calls consistent. Is this normal? Below is my code:
useEffect (() => {
fetch(`https://free.currconv.com/api/v7/convert?q=${currencyOne}_${currencyTwo}&compact=ultra&apiKey={-------}\`)
.then(response => response.json())
.then(data => {
console.log(data)
//`${props.currencyFirst}_${props.currencySecond}`
const exchangeHolder = data[`${props.currencyFirst}_${props.currencySecond}`];
setExchange(exchangeHolder);
console.log(exchangeHolder)
})
.catch(error => console.error(error))
}, [])
View all comments
Show parent comment
1
u/DrakeJohnsonPHD Mar 25 '22
Ok, is there a way to auto load from VS to sandbox