Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda