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

247
Views
How to return a tag from a method in react js?

I want to return a tag from a method so that once I call the method the tags are returned and these tags are used to call a component.

const Populate =() =>
{
  let tags = [];
  analysisinfo.forEach((_item,index) =>
  {
   if(analysisinfo[index].id!== defaultid)
    tags.push(<AU props={analysisinfo[index]} instance ={index}/>);
    console.log({tags});
   }
 return tags;

let me explain in-detail the analysisinfo is an useState array which contains the below values. These values are being passed into this method.

0:
cpu: true
hdd: true
id: "00000000000000000000000000000000"
ram: true 

And pushes these values into tags[]. I want them pushed into array in the form of a <>, so that when I return it calls the <AU..../> tag component which takes the above values as props.

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

0

Use a combination of filter and map:

const Populate = () => (
    <>
        { 
            analysisinfo
                .filter(i => i.id !== defaultid)
                .map((i, idx) => (
                    <AU props={i} instance={idx} />
                ))
         }
    </>
);
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!