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

128
Views
displaying array data in react. output is not coming

when I am printing console.log(response.data) in console below output is coming.

enter image description here

I created one hook const [result,setResult] = useState([]);

and then output of API I set as

setResult(response.data);

when I am writing below code it is just printing " Data is". it is not printing output of result

              <h1>
                  Data is
               {
                   result.map((res:any)=>{
                       {res.id};
                   })
                }    

              </h1>  

what mistake I am doing?

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

0

The whole logic of your code it's okay. You are using the useState Hook correctly. And the data your passing to the state is an array which will work fine with the map() method. The only problem I'm seeing is that your map() method is not well implemented.

Try this instead:

<h1>
  Data is
  {
   result.map((res:any)=>{
      return <p>{res.id}</p>
   })
  }    
</h1>  

The map() method always returns something. When it is a one liner it is not necessary to type return.

<h1>
  Data is
  {
   result.map((res:any) => res.id )
  }    
</h1>  

To print multiple properties of the object:

<h1>
  Data is
  {
   result.map((res:any) => {
      return [
        <div key={res.id}>
           <p>{res.id}</p>
           <p>{res.name}</p>
           <p>{res.createdAt}</p>
        </div>
      ]
   })
  }    
</h1>  
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!