I am calling following function to get a list of saved cards. fetch function return a Promise Object. I want to convert it to a string[] and return. Is this a possible thing to do?
const fetchSavedCards = (): string[] => {
return fetch("/fetchSavedCards")
.catch((error: Error) => {
throw new Error(error.message);
})
.then((response) => {
return response.json();
})
.then((cards: string[]) => {
return cards;
});
};
The returned result set is then need to be displayed in a web page. But .map() function does not work with Promise object.
<CardContent>
<label> Card Selection </label>
<div className="container" id="cards">
{Service.fetchSavedCards().map(
(card) => <label>
<input type="radio" name="selectedCard" value="test" onChange={this.handleCardSelectionChange}/>
{card}
</label>)}
</div>
...
</CardContent>