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

112
Visualizações
Why is this react array not being overwritten after each loop?

I have this piece of code which calls one of two functions to return some JSX which is then added to an array to be displayed later in the function. The problem that I am having is that on each loop through the inputs array in subsections is not being overwritten and as such the inputs for other subsections are being added to the final array multiple times.

Any advice or direction on where to look to solve this problem would be greatly appreciated.

// Subsections
for (let i = 0; i < pageComponent['subsections'].length; i++) {
    let subsectionComponent = pageComponent['subsections'][i];
    let inputs = [];

    // Inputs
    for (let k = 0; k < subsectionComponent['questions'].length; k++) {
        let questionComponent = subsectionComponent['questions'][k]
        if (questionComponent['type'] === 'TextArea') {
            this[inputs].push(this.addTextArea(questionComponent));
        } else {
            this[inputs].push(this.addInput(questionComponent));
        }
    }
    subsectionInputs.push(<div key={i+"_subgroup_div"} className="form-group row">
        <h3 style={{margin: 15}}>{subsectionComponent[0]}</h3>
        {this[inputs]}
    </div>);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're referencing this[inputs] when I think you just intend to reference inputs directly.

if (questionComponent['type'] === 'TextArea') {
    inputs.push(this.addTextArea(questionComponent));
} else {
    inputs.push(this.addInput(questionComponent));
}

And here:

subsectionInputs.push(<div key={i+"_subgroup_div"} className="form-group row">
    <h3 style={{margin: 15}}>{subsectionComponent[0]}</h3>
    {inputs}
</div>);
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