Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda