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

203
Vistas
TypeError: utilData.map is not a function issue

I have the following code within my React component:

  const [utilData, setUtilData] = useState([]);

  useEffect(() => {    
      ws.current.onmessage = e => {
          const data = JSON.parse(e.data);
          console.log("data: ",data);
          setUtilData(data)          
      };
  }, []);

The console.log of data returns the following information, which should be stored within the utilData state.

[
    {
        "env_name": "the-matrix",
        "score_one": 24,
        "memory": 1024,
        "cpu_temp": 66.4
    }
]

The issue that I am not sure about and can't see what I am doing wrong, is when I attempt to access each property using the .map array method over utilData, i.e:

  return (
    <div>
        {
          utilData.map((data, i) => (
            <span>{data.env_name}</span>
          ))
        }

    </div>
  )

I am getting the error: TypeError: utilData.map is not a function and unsure why

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

update return below snippet, since initially utildata might ben ull

return (
    <div>
        {
          utilData ? utilData.map((data, i) => (
            <span>{data.env_name}</span>
          )) : null
        }

    </div>
  )
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