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

260
Views
Cómo configurar || operador con jsx? Reaccionar

Necesito configurar dos si con React este es mi código:

 <div> {item?.status === "One" || (item?.status === "Two" && ( <Button btn="primary" title="One text" /> ))} <Button btn="primary" title="Two text" /> </div>

Necesito renderizar el primer botón si item.status === "Uno" o ( || ) "Dos", pero ¿esto no funciona? ¿Dónde está el problema?

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

0

¿Por qué no lo intentas?

 <div> {(item?.status === "One" || item?.status === "Two") && ( <Button btn="primary" title="One text" /> )} <Button btn="primary" title="Two text" /> </div>;

Había encapsulado (item?.status === "Two" && <Button btn="primary" title="One text" />) lo que puede causar un problema con su lógica.

about 4 years ago · Juan Pablo Isaza Report

0

Arregle su paréntesis para su condición de renderizado. Debe envolver su expresión booleana y la declaración de código como {(boolean expressions) && (code statements)} :

 <div> { (item?.status === "One" || item?.status === "Two") && ( <Button btn="primary" title="One text" /> ) } <Button btn="primary" title="Two text" /> </div>

La separación de líneas para los paréntesis y las llaves es solo una preferencia estilística mía.

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!