Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

385
Visualizações
React, Axios, PokeAPI: undefined reading Map

To improve my React skills I was following this tutorial to how create a list of name using PokeAPI.

I am stopped at 11.35, because I put this code as the tutorial show (the first block is from App.js, the second is from a component call PokemonList.js) :

function App() {
  const [pokemon, setPokemon] = useState([])

  useEffect(()=>{

    axios.get("https://pokeapi.co/api/v2/pokemon").then(res=> {
      setPokemon(res.data.result.map(p => p.name))
    })
  }, [])
  
   return (
    <PokemonList pokemon={pokemon}/>
  );
}

export default App;

  
    

export default function PokemonList({pokemon}){
    return (
        <div>
            {pokemon.map(p => (
                <div key={p}>{p}</div>
            ))}
        </div>
    )
}

But in the console I have the error message: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'map')

I have understand that I need to put a Promise.all in App.js (I found a similar question before to asking) but I have not clear how I must change in the PokemonList component to print the list on screen.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is a typo. You have to change from result to results.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda