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

231
Views
data.map is not a function typerror in cart
const Cart = ({ details }) => {
  let { loading, data } = details;

  console.log(data);
  

  return (
    <div>
      {loading ? (
        <p>Load</p>
      ) : (
        <table>
          <thead>
            <tr>
              <th>Id</th>
              <th>Title</th>
              <th>Completed</th>
            </tr>
          </thead>
          <tbody>
            {data.map((d) => {
              return (
                <tr key={d.id}>
                  <td>{d.id}</td>
                  <td>{d.title}</td>
                  <td>{d.completed ? "OK" : ""}</td>
                </tr>
              );
            })}
          </tbody>
        </table>
      )}
    </div>
  );
};

export default Cart;

console log of details is:

{
    loading: false, data: {…}}
    data: {data: Array(3)}
    loading: false
   "=================" 

console log of data is

{data: Array(3)}

data: Array(3)
0: {userId: 1, id: 1, title: 'delectus aut autem', completed: false}
1: {userId: 1, id: 2, title: 'quis ut nam facilis et officia qui', completed: false}
2: {userId: 1, id: 3, title: 'fugiat veniam minus', completed: false}
length: 3

I am getting error:

Uncaught TypeError: data.map is not a function
at Cart

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As you said "console log of data is {data: Array(3)}" so "data" is an Object, not an Array.

try data.data.map((d) => {...})

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!