Guest User

reducer

a guest
Apr 23rd, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. export const GET_POKEMON_LIST = 'GET_POKEMON_LIST';
  2. export const SET_POKEMON_LIST_ERROR_SUCCESS = 'SET_POKEMON_LIST_ERROR_SUCCESS';
  3. export const SET_POKEMON_LIST_ERROR = 'SET_POKEMON_LIST_ERROR';
  4.  
  5. export const initialPokemonListState = {
  6. pokemonList: {},
  7. pokemonListLoading: true,
  8. pokemonListError: false,
  9. pokeListUrl: 'https://pokeapi.co/api/v2/pokemon/?limit=0&offset=0',
  10. }
  11.  
  12. export const pokemonListReducer = (state, action) => {
  13. switch (action.type) {
  14. case GET_POKEMON_LIST:
  15. return {
  16. pokemonList: {},
  17. pokemonListLoading: true,
  18. pokemonListError: false,
  19. }
  20.  
  21. case SET_POKEMON_LIST_ERROR_SUCCESS:
  22. return {
  23. pokemonList: action.payload,
  24. pokemonListLoading: false,
  25. pokemonListError: false,
  26. }
  27.  
  28. case SET_POKEMON_LIST_ERROR:
  29. return {
  30. pokemonListLoading: false,
  31. pokemonListError: true,
  32. }
  33.  
  34. default:
  35. return state;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment