0

What is the best way to avoid receiving the error no nested ternary on typescript.

                  disablePortal
                  options={
                    // eslint-disable-next-line no-nested-ternary
                    units=== "mm"
                      ? valuesMm
                      : units === "km"
                      ? valueskm
                      : valuesls
                  }

I tried using this but it is giving an error

options={
                    units=== "mm"
                      ? valuesMm
                      : [
                          units.slumpUnit === "cm"
                            ? valuesCm
                            : valuesIn,
                        ]
                  }
Tanu
  • 1,286
  • 4
  • 16
  • 35

1 Answers1

0

I could easily see this as a place one could decide to ignore the rule and nest it - but if you don't want the nesting, another option is to put the logic into an IIFE and return the values conditionally.

options={(() => {
  if (units=== 'mm') return valuesMm;
  if (units === 'km') return valueskm;
  return valuesls;
})()}
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320