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

248
Views
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>
    );
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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]))
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!