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

168
Vistas
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data'), map is not working?

I have a API this is working fine in console. but when I'm using map this is not working giving error.

Getting this error:- enter image description here

My Code:-

function GetEgyptStates() {
  const [egyptData, setEgyptData] = React.useState(null);

  React.useEffect(() => {
    axios.get('http://localhost:3000/states-and-districts.json').then((response) => {
      setEgyptData(response.data);
      console.log(response.data.Egypt.Assuit);
    });
  }, []);

  if (!egyptData) return null;

  return (
    <div>
        {egyptData.response.data.Egypt.Assuit.map((item) => (
          <li>{item}</li>
        ))}
    </div>
  );
}

ThankYou for your Support!

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

0

   function GetEgyptStates() {
  const [egyptData, setEgyptData] = React.useState(null);

  React.useEffect(() => {
    axios.get('http://localhost:3000/states-and-districts.json').then((response) => {
      setEgyptData(response.data);
      console.log(response.data.Egypt.Assuit);
    });
  }, []);

  if (!egyptData) return null;

  return (
    <div>
        {egyptData.Egypt.Assuit.map((item) => (
          <li>{item}</li>
        ))}
    </div>
  );
}

Try this. You are already setting the response data using response.data in state therefor you don't need to use response.data again

Further, if this doesn't work, then please post a screenshot of api response from console in question.

Thanks,

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