I trying to do a little project making a mini Pokedex to get more familiar with hooks and Axios. I'm trying to pass the Pokemon's URLs given by PokeAPI in order to have an array of Pokemon objects to display all their information. This is the code I have now, but it returns an array of 20 "undefined" elements.
const [pokemon, setPokemone] = useState([]);
axios.get('https://pokeapi.co/api/v2/pokemon/')
.then(res => {
setPokemon(res.data.results.map(p => {
axios.get(p.url)
.then(res => res.data);
}));
});
What could I do, or what am I doing wrong? If I console.log the "res.data" it prints all the objects, but for some reason that information doesn't get set.
Thanks in advance for any help/suggestions.