Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!