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

397
Vistas
Mixed operators in JSX

I'd like to use mixed operators in JSX, for example:

{datas && datas.map(function(data,i){ return <MyComponent key={i} />}) || []}

While this technically works, ES lint warns of 'no-mixed-operators'. Is this a safe pattern to use in JSX?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

From the ESLint documentation:

Disallow mixes of different operators (no-mixed-operators)

Enclosing complex expressions by parentheses clarifies the developer’s intention, which makes the code more readable. This rule warns when different operators are used consecutively without parentheses in an expression.

var foo = a && b || c || d;    /*BAD: Unexpected mix of '&&' and '||'.*/
var foo = (a && b) || c || d;  /*GOOD*/
var foo = a && (b || c || d);  /*GOOD*/

If you don’t want to be notified about mixed operators, then it’s safe to disable this rule.

Hope this helps.

over 4 years ago · Santiago Trujillo Denunciar

0

You can just Wrap in the parenthesis like this. It not going to show that warning.

{datas && (datas.map(function(data,i){ return <MyComponent key={i} />}) || [])}

It worked for me.

over 4 years ago · Santiago Trujillo 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