Last active
March 7, 2020 19:33
-
-
Save vhuerta/6263a50c1a99df416e2429d8b5cc3807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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