public async Task<List<TodoItem>> RefreshDataAsync ()
{
...
var uri = new Uri (string.Format (Constants.TodoItemsUrl, string.Empty));
...
var response = await _client.GetAsync (uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync ();
Items = JsonConvert.DeserializeObject <List<TodoItem>> (content);
}
...
}
async componentDidMount() {
//Have a try and catch block for catching errors.
try {
//Assign the promise unresolved first then get the data using the json method.
const pokemonApiCall = await fetch('https://pokeapi.co/api/v2/pokemon/');
const pokemon = await pokemonApiCall.json();
this.setState({pokeList: pokemon.results, loading: false});
} catch(err) {
console.log("Error fetching data-----------", err);