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

151
Visualizações
Need to improve JS function using a few || (logical or) or mayby another solution

I have function it works good but I want to improve that

  const canPrepareReview = (): boolean => {
if (loading) return true;
if (Object.keys(assets).length !== 0) return true;
return master;

}

  <Button
    disabled={!canPrepareReview()}
  >

I try to use something like this

  <Button
    disabled={loading || master || Object.keys(assetsSelected).length === 0}
  >     

but it does not work So any ideas on how it can be improved?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The function evaluates:

loading || Object.keys(assets).length !== 0 || master

But in the first disabled attribute, the function result is negated, so we evaluate:

!(loading || Object.keys(assets).length !== 0 || master)

If you put that as expression in the disabled attribute, it should give equivalent behaviour as in the function-based solution.

However, defining the function is actually better practice. Don't bloat attributes with complex expressions.

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