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

280
Views
How to print html text depending on condition using reactJs?

simple question here having this :

<Row>
   { "Client : " && elt.client?.libelle}
</Row>

I'd like that if elt.client is defined, displaying :

Client : client libelle

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

0

Not sure exactly what you mean, but maybe this help?

<Row>
  {elt.client ? elt.client.libelle : elseStatement}
</Row>

Meaning: `if (elt.client) { return elt.client.libelle } else { return "whatever else you want" }

`

about 4 years ago · Juan Pablo Isaza Report

0

You can make use of ternary operator (? and : ). This operator is frequently used as an alternative to an if...else statement.

<Row>
 { elt?.client?.libelle ? ("Client : " + elt.client.libelle) : "" }
</Row>

It takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy.

Also, you can utilise optional chaining (?.) operator of JavaScript which prevents an error if a reference is nullish (null or undefined).

In this case, if elt is undefined, it won't throw error. Hence, if all elt, elt.client and elt.client.libelle is defined and the value is no null, "Client : " + elt.client.libelle will display.

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!