Unverified Commit 2d995363 authored by Michal Čaniga's avatar Michal Čaniga
Browse files

Add pokemon fetcher, data

parent 8bef74ec
export type Food = {
name: string;
price: number;
restores: number;
image?: string;
};
// export const food: Food[] = [{}, {}, {}];
export type Pokeballs = {
name: string;
price: number;
};
// export const pokeballs: Pokeballs[] = [{}, {}, {}];
export type Pokemon = {
id: number;
name: string;
sprite: string;
};
export type PokemonResponse = {
id: number;
name: string;
sprites: any;
};
export const getPokemons = async () => {
const ids = Array.from({ length: 151 }, (_, i) => i + 1);
const pokemons = Promise.all(
ids.map(async id => {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const pokemonDetail = await response.json();
console.log(transformPokemon(pokemonDetail));
return transformPokemon(pokemonDetail);
})
);
console.log(await pokemons);
};
// TODO: modify this function to get everything we want from the API, provide custom fields if desired
const transformPokemon = (pokemon: PokemonResponse) => {
const { id, name, sprites } = pokemon;
return { id, name, sprite: sprites.front_default };
};
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment