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

272
Views
Reactjs - App.js:34 TypeError no detectado: ch.map no es una función

Obtengo que ch.map no es un error de función en mi archivo application.js mientras realizo una solicitud GET simple desde una API Rest:

 function App() { const [ch, setCh] = useState([]); useEffect(()=>{ fetch("https://localhost:12354/api/v1/Objects", { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic YWRt' } }) .then( resp => resp.json()) .then( resp => setCh(resp)) .catch( error => console.log(error)) }, []) return ( <div className="App"> <header className="App-header"> <h1>Object Manager</h1> </header> <div className = 'layout'> <div> { ch.map( i => { return <h2>{i.Name}</h2> })} </div> <div> Object Details </div> </div> </div> ); }

Y aquí está el resultado de la misma llamada a la API del cartero. Estoy tratando de obtener el "Nombre" en mi javascript anterior:

 { "@odata.context": "$metadata#Object", "value": [ { "@odata.etag": "W/\"24979988a17d428c\"", "Name": "Load Actual", "StartTime": "2021-12-23T22:46:24+10:00", "DSTSensitive": true, "Active": true, "ExecutionMode": "MultipleCommit", "Frequency": "P1DT00H00M00S", "Attributes": { "Caption": "Load Actual" } } ] }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cambie setCh(resp) a setCh(resp.value) . Cuando llama a setCh(resp) , está configurando ch para que sea igual a la respuesta completa json. Eso significa que es el mapa con las claves @odata.context y value . El mapa de métodos no existe en un objeto, pero sí en el valor resp., que es una matriz.

about 4 years ago · Santiago Trujillo 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!