Skip to content

Instantly share code, notes, and snippets.

@vhuerta
Last active March 7, 2020 19:33
Show Gist options
  • Select an option

  • Save vhuerta/6263a50c1a99df416e2429d8b5cc3807 to your computer and use it in GitHub Desktop.

Select an option

Save vhuerta/6263a50c1a99df416e2429d8b5cc3807 to your computer and use it in GitHub Desktop.
// ACTION CREATORS
export const fetchPokemons = () => {
return async (dispatch: Dispatch<PokemonAction>) => {
dispatch({ type: "FETCH_POKEMON_PENDING" });
try {
const result: { results: Pokemon[] } = await (await fetch(
"https://pokeapi.co/api/v2/pokemon"
)).json();
dispatch({ type: "FETCH_POKEMON_COMPLETED", pokemons: result.results });
} catch {
dispatch({ type: "FETCH_POKEMON_FAILED" });
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment