Search code examples
ternary

Need some help to refactor ternary


i did this ternary operator and this works but i know it could be better. If anyone can help me to refactor this code, that will be great

disabled={ mainCurrency.code
              ? currency.code
                 ? currency.code === mainCurrency.code
                   ? true
                   : false
                 : true
               : true
          }

Solution

  • So if mainCurrency is not set or currency is not set or mainCurrency is equal to currency than it is true. Writing it out would be

    !mainCurrency.code || !currency.code || currency.code === mainCurrency.code