I need to use an async function in my render() function in React. How could I do that? What I am getting now is just a Promise, obviously.
import React, { Component } from "react";
export default class FlagImage extends Component {
getSrc = async name => {
const url = `https://restcountries.eu/rest/v2/alpha/${name}`;
const res = await fetch(url);
const json = res.json();
const flagURL = json.flag;
return flagURL;
};
render() {
const { name } = this.props;
return name ? <img alt={`Flag ${name}`} src={this.getSrc(name)} /> : <div />;
}
}