Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

100
Vistas
TypeError: n.map is not a function

I am trying to return the data from this fetch in some cards in another component, but I get the following error:

TypeError: n.map is not a function.

I guess it's because of the async/await, but I don't know how to fix it.

Thanks a lot

export default function Container(){

    const [flights, getNewFlights] = useState({});

    const user = sessionStorage.getItem("username");
    const tipouser = sessionStorage.getItem("TipoUser");
    const APT = sessionStorage.getItem("Base");
    const Fecha = sessionStorage.getItem("Fecha");

    const fetchFlights = async () => {
        try {
          const flightsData = await $.ajax({
                url: "https://listVuelos.php",
                type: 'POST',
                data: {
                  APT,
                  Fecha
                }

            })
            getNewFlights(JSON.parse(flightsData))
        } catch (err) {
          console.log("Da error")
        }
      };

      useEffect(() => {
    
        fetchFlights()
    
        const interval = setInterval(() => {
          fetchFlights()
        }, 100000)
        return () => interval
    
      }, []);

    return(
      <Fragment>
      <div className="div_container">
         { flights?.map ( f => <IndexCards  data={f}></IndexCards> )}
      </div>
  </Fragment>
    );
}
7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you can't use map function on an object to overcome the problem you can do something like this:

Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, newValue]))
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.