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

118
Views
Accessing array element from response data using react-query

I am using react-query to make a GET request to my API in which the response is an array of objects. Each object has 1 property which is the name that I want to access. When I log the response to the console, it appears like the image listed at the bottom. Even says the prototype is an array. However, when I try to access an element of the response, it says "cannot read properties of undefined".

Here is the code which displays the data as shown in the image:

const { isLoading, error, data } = useQuery('cat_names', () =>
        fetch('<api-link>').then(res =>
            res.json()
        )
    )
console.log(data)

Here is the code I used to try accessing the first element of the array.

const { isLoading, error, data } = useQuery('cat_names', () =>
   fetch('<api-link>').then(res =>
       res.json()
   )
)
console.log(data[0])

I have also tried mapping data, with no luck:

const mapped_data = data.map(element => element.name)
console.log(mapped_data)

enter image description here

about 4 years ago · Juan Pablo Isaza
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!