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

155
Views
How to use optional chaining for deeply nested values in react where ternary operator used for conditional rendering?

I have this deeply nested value

eventsubcategoryvalue: data.body.spending.requestspend==='y' ? data.body.spending.allowspend : chargeamount

so here eventsubcategoryvalue is decided on basis of result of the ternary operator. I want to use optional chaining here instead of having this complex nested thing. How can I re write it? I am unable to understand even after going through the MDN doc.

How can one rewrite this with optional chaining?

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

0

Try

(eventsubcategoryvalue) ? ( data.body.spending.requestspend === 'y' ? data.body.spending.allowspend : chargeamount ) : chargeamount 
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!