Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

315
Vistas
Unhandled Runtime Error TypeError: subSector.map is not a function

I'm unable to map through json data from a fake api. It's working when returning more than one data but this error happens when the data is a single object.

Here is my code:

    {subSector
     ? subSector.map((sector) => (
//               ^ ~ subSector.map is not a function
         <MenuItem value={sector.id}>{sector.email}</MenuItem>
       ))
    : "nodata"}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

By using map on subSector, you are assuming it is an array of items and not a single item.

You are seeing the error because subSector is not an array, and therefore does not have the map function available.

Instead, either access the subSector properties directly (assuming subSector is a single item):

    {subSector ? (
         <MenuItem value={subSector.id}>{subSector.email}</MenuItem>
       )
    : "nodata"}

or handle both cases where it could be an array or single item:

    {Array.isArray(subSector)
     ? subSector.map((sector) => (
         <MenuItem value={sector.id}>{sector.email}</MenuItem>
       ))
    : subSector ? (
         <MenuItem value={subSector.id}>{subSector.email}</MenuItem>
       ) 
    : "nodata"}

or, as catgirlkelly says, ensure your fake data always returns an array, even for a single item.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda