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

431
Views
Uncaught error: TypeError: data.map is not a function

Could you please help me here? I want to map through a response object (example below). I don't have any errors in VSC but in browser there is an error: Uncaught error: TypeError: data.map is not a function

{
  "title":"some title",
  "info":"some info",
  "users":
  [
    {
      "id":1,
      "name":"name1",
      "surname":"surname1",
      "email":"email1",
    },
    {
      "id":2,
      "name":"name2",
      "surname":"surname2",
      "email":"email2",
    },
 ....
  ],
"resource":
{
  "url":"some url",
  "description":"some description"
  }
}

here is my interfaces:

export interface IUsers {
  id: number,
  name: string,
  surname: string,
  email: string
}

export interface IData {
  title: string,
  info: string,
  users: IUsers,
  resource: {
    url: string,
    description: string
  }
}

What i've got for now:

const { data } = DataAPI.useFetchAllDataQuery('')
...
{data  && data.map(item => item.users.map(user => (
 <User user={user} key={user.id}/>)))}

should i try data.users.map(...) --> property 'users' doesn't exist on type IData[].

May be it's because of the fact that 'data' is not an array, but i'm not sure how to use this construction Object.entries(data).map()...

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Can you try doing something like this?

const { data } = await DataAPI.useFetchAllDataQuery('') // Assuming this is a promise
{data && data.users.map(user => (<User user={user} key={user.id}>))}

or maybe optional chaining

{data?.users?.map(user => (<User user={user} key={user.id}>))}
about 4 years ago · Santiago Gelvez 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!