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

193
Views
TypeError: no se pueden leer las propiedades de undefined (leyendo 'mapa') NEXTJS

Estoy tratando de obtener una imagen de esta API usando getStaticProps pero parece que no puedo obtenerla.

Si agrego un '?' al código como este, en el registro dice 'indefinido'. ¿Por qué no puedo ir a buscarlo?

 <div> {hotelPics.map((hotelpic)=> ( <Image src={hotelpic.url} /> ))} </div>

Este es el código:

 import Image from 'next/image'; import React from 'react' function Images({hotelPics }) { console.log(hotelPics); return ( <div> {hotelPics.map((hotelpic)=> ( <Image src={hotelpic.url}/> ))} </div> ) } export async function getStaticProps() { const res= await fetch ('https://obmng.dbm.guestline.net/api/hotels?collection-id=OBMNG') const hotelPics = await res.json() return { props: { hotelPics, }, } } export default Images
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

getStaticProps se están "compilando" en el momento de la compilación, por lo que debe verificar la variable isFallback

Además, tiene una matriz de images anidadas en la matriz hotelPics devuelta por getStaticProps

 import Image from 'next/image'; import { useRouter } from 'next/router'; import React from 'react' function Images({hotelPics}) { const router = useRouter(); if (router.isFallback) { return <h1>Loading...</h1>; } //console.log(hotelPics.images) return ( <div> {hotelPics.map((hotelpic)=> ( hotelpic.images.map((image) => ( //replace here with Image tag <p key={image.url}>{image.url}</p> ) ) ))} </div> ) } export async function getStaticProps() { const res= await fetch ('https://obmng.dbm.guestline.net/api/hotels?collection-id=OBMNG') const hotelPics = await res.json() return { props: { hotelPics, }, } } export default Images
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!