Created
August 16, 2021 17:07
-
-
Save eliezerfot123/df0cd5487a053506c873f5663a653a41 to your computer and use it in GitHub Desktop.
pokeDucks
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
/* 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