Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
cómo mapear una API en un párrafo

Hola, estoy tratando de mapear una matriz de una API para mostrar párrafos para cada índice dentro de la matriz. Sin embargo, sigo recibiendo un error:

**> TypeError: undefined no es un objeto (evaluando

'post.game_indices.version.name')**

Pero cuando registro una publicación en la consola y uso mis botones debajo, muestra lo que quiero y no indefinido. Entonces, ¿por qué no está definido cuando quiero mapear los párrafos?

'''

importar React, {useEffect,useState} desde 'react' importar instancia de './axios'

constante Inicio = () => {

 const [post, setPost] = useState(null); const [error,setError] = useState(null); const [showTypes,setShowTypes]=useState(false); const [showAbilities,setShowAbilities]=useState(false); useEffect(() => { instance.get("bulbasaur/").then((response) => { setPost(response.data); }).catch(error => { setError(error); }) },[]); console.log(post); if (error) return `Error: ${error.message}`; if (!post) return 'no post!' return ( <> <h1>{post.name}</h1> <button onClick={()=>setShowTypes(!showTypes)}>types</button> {showTypes? <p>{(post.types[0].type.name)}</p>:null} {showTypes? <p>{(post.types[1].type.name)}</p>:null} <button onClick={()=>setShowAbilities(!showAbilities)}>abilities</button> {showAbilities? <p>{(post.abilities[0].ability.name)}</p>:null} {showAbilities? <p>{(post.abilities[1].ability.name)}</p>:null} {/* <button onClick={gameVersion}>game versions</button> */} {post.game_indices.version.name.map(name => <p key={post.game_indices.version.name}>{name}</p>)} </> )

}

exportar Inicio predeterminado;

'''

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El error proviene del hecho de que su version no es un objeto en game_indices (no está undefined , lo que significa que tal vez game_indices es un objeto vacío o no contiene la clave de version ). ¿Puedes verificar tu objeto post nuevamente?

about 4 years ago · Juan Pablo Isaza Report

0

bien, recreé su aplicación y encontré un problema: debe mapear en la matriz post.game_indices y luego mostrar index.version.name

 {post.game_indices.map((index, idx) => <p key={idx}>{index.version.name}</p>)}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!