Skip to content

Instantly share code, notes, and snippets.

@vhuerta
Created March 7, 2020 19:29
Show Gist options
  • Save vhuerta/3b34eb5c12be9abdb51886ee84e9501f to your computer and use it in GitHub Desktop.
Save vhuerta/3b34eb5c12be9abdb51886ee84e9501f to your computer and use it in GitHub Desktop.
// REDUCER
function reducer(state: PokemonState, action: PokemonAction): PokemonState {
switch (action.type) {
case "FETCH_POKEMON_PENDING":
return { ...state, isLoading: true };
case "FETCH_POKEMON_COMPLETED":
return { ...state, isLoading: false, pokemons: action.pokemons };
case "FETCH_POKEMON_FAILED":
return { ...state, isLoading: false, pokemons: [] };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment