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

133
Views
Nested ternary operator for react components

I want to come up with a nested if ternary operator with react components but am being challenged , this is my logic :

if (value==='bank' && is_valid_iban && is_completed) {

return <Checked/>

}

else if (is_completed) {

return <Checked/>
}

else if (value==='businessplan' && is_required) {

return <NotChecked/>
}

This was my change :

{
(!value=== 'bank' || is_valid_iban) &&
                is_completed ? (<Checked/>) : (value ==='businessplan' && is_required && (<NotChecked/>))

}

What could be the best way of coming up with a ternary operator for the logic above.

Thanks

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Make it Simple:

  {(value === "bank" && is_valid_iban && is_completed) || is_completed ? (
    <Checked />
  ) : (value === "businessplan" && is_required) ? (
    <NotChecked />
  ) : (
    <NotChecked />
  )}
about 4 years ago · Juan Pablo Isaza Report

0

This solution seeks to simplify the below given set of conditions:

if (value==='bank' && is_valid_iban && is_completed) {
  return <Checked/>
} else if (is_completed) {
  return <Checked/>
} else if (value==='businessplan' && is_required) {
  return <NotChecked/>
}

It is observed from the above that is_completed is part of the first & second conditions. Something like this: ((A && B && C) || C) which can be represented as (A && B) || C.

Using a standard if..else structure:

if ((value === 'bank' && is_valid_iban) || is_completed) return <Checked />
else if (value === 'businessplan' && is_required) return <NotChecked />
else return null;

Using ternary ?:

return (
  ((value === 'bank' && is_valid_iban) || is_completed)
  ? <Checked />
  : (value === 'businessplan' && is_required)
    ? <NotChecked />
    : null
);

When using ?: please always indent the code so it is readable. Same applies for if else as well; however, the if else structure is a lot more readable than ?:.

about 4 years ago · Juan Pablo Isaza 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!