Skip to content

Instantly share code, notes, and snippets.

@eliezerfot123
Created August 16, 2021 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliezerfot123/df0cd5487a053506c873f5663a653a41 to your computer and use it in GitHub Desktop.
Save eliezerfot123/df0cd5487a053506c873f5663a653a41 to your computer and use it in GitHub Desktop.
pokeDucks
/* en la metodología de ducks siempre vamos a tener 3 fases por app: Constantes, reducer y acciones*/
import axios from "axios";
import { act } from "react-dom/cjs/react-dom-test-utils.production.min";
// Constantes
const dataInicial = {
array: []
}
// esto son los types
const OBTENER_POKEMONES_EXITO = 'OBTENER_POKEMONES_EXITO'
//Reducer
export default function pokeReducer(state = dataInicial, action){
switch(action.type){
case OBTENER_POKEMONES_EXITO:
return {...state, array: action.payload}
default:
return state
}
}
//Acciones
export const obtenerPokemonesAccion = () => async (dispatch, getState) => {
try{
const res = await axios.get('https://pokeapi.co/api/v2/pokemon?offset=0&limit=20')
dispatch({
type: OBTENER_POKEMONES_EXITO,
payload: res.data.result
})
}catch(error){
console.log(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment