Ok, I have async function, which get data about cryptocurrency. And when I load page at first time, data is undefined. But, if I change something in code (for example: set insignificant Enter) data is appears.
How change my code to get data with statr page?
const getData = async () => {
try {
const resCoins = []
for (let coinName of coinsName){
let coin = await axios.get('https://api.coingecko.com/api/v3/coins/' + coinName)
resCoins.push(coin.data)
}
let usd = {symbol: 'usd', market_data: {current_price: {}}}
for (let currency of resCoins){
usd.market_data.current_price[currency.id] = 1 / currency.market_data.current_price.usd
}
resCoins.push(usd)
setCoins(resCoins);
} catch (error) {
console.error(error);
}
};