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

68
Visualizações
loop through list from backend

I have list from backend. I want to loop through all the elements of this list and hide the button if it has no status 6.

response

Returning from the response in the incoming list. It won't always be like this. It can come in 7 elements.

policyInstallmentDtoList: Array(1)
 0:
 amount: 291
 currency: "TRY"
 date: "10-02-2022"
 installmentNumber: 1
 status: "3"

I'm trying to loop through the list here.

useEffect(() => {
 if (paymentInfoData?.policyInstallmentDtoList?.forEach((e) => e['status'] !== '6')) {
   setHiddenControlButtonClass('hidden');
 }
}

html

<div className={hiddenControlButtonClass}>
  <AS.Button variant="outlined" onClick={handlePayment}>
    Devam
  </AS.Button>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use Array.some

It's a built-in method in JS's array prototype which returns a boolean value that represents whether or not at-least a single member in the array answers your condition.

useEffect(() => {
 if (!paymentInfoData?.policyInstallmentDtoList?.some(e => e.['status'] === '6') {
   setHiddenControlButtonClass('hidden');
 }
}

This should work just fine and only set the state once,
which is better for performance.

about 4 years ago · Juan Pablo Isaza Relatório

0

You don't need to put the forEach method in an if statement.

useEffect(() => {
  paymentInfoData?.policyInstallmentDtoList?.forEach((e) => {
    if (e.status !== '6') {
      setHiddenControlButtonClass('hidden');
    }
  }
}
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