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

238
Visualizações
React Typescript: Array does not map through all items

I have following Table / Array: enter image description here

If I press the blue button, then all items with the same group as the record should change the Status (Gratis). But now it just change the Value of the Record and all items above it. As an example, if I press the Button on Record No. 1 then itselft and all above (No. 0) get an change of the Status (Gratis).

Following code im using to go through the array and change the Status:

private _updateFreeStatus = (record: QuestionModel): void => {
        fetch('api/Test/UpdateGratisStatus', {
            headers: { 'Content-Type': 'application/json' },
            method: 'PUT',
            body: JSON.stringify({
                'group': record.group,
                'free': record.free,
            })
        });
        this.state.question.map(item => {
            if (item.group === record.group)
            {
                item.free = !record.free;
            }
        });
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. do not mutate the state
  2. create a copy, and use setState

Use

const updatedQuestions = this.state.question.map(item => {
  if (item.group === record.group) {
    return {
       ...item,
       free: !record.free
    }
  }
  return item;
});

this.setState({question: updatedQuestions});
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