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

184
Views
Cómo renderizar un elemento diferente basado en una condición (reaccionar jsx)

Quiero mostrar un botón determinado dentro de una tabla de datos en la interfaz de usuario en función de una condición

pseudocódigo

 if assessment.category is complete //show success button if assessment.category is not complete //show failed button if assessment.category is in progress //show in progress button if assessment.category is rejected //show rejected button

(JSX)

 <td> {assessment.categoryCategory === 'Complete' && <button type="button" className="btn btn-success">Complete</button> } {assessment.categoryCategory === 'Not Complete' && <button type="button" className="btn btn-info">Not Completed</button> } {assessment.categoryCategory === 'In Progress' && <button type="button" className="btn btn-warning">WIP</button> } {assessment.categoryCategory === 'Rejected' && <button type="button" className="btn btn-danger">Rejected</button> } </td>

Sin embargo, esto está mal. Lanza un error. Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

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

0

const btnMap = { complete : { key: 'warning', label: 'Completed' }, 'not complete' : { key: 'info', label: 'Not Completed' }, progress : { key: 'warning', label: 'WIP'}, rejected : { key: 'danger', label: 'Rejected' }, // easy to add additional values if needed. } const btnItem = btnMap[assestment.category || 'not progress']; //set a default value if you believe could be undefined.
 <button type="button" className={`btn btn-${btnItem.key}`}> {btnItem.label} </button>
about 4 years ago · Juan Pablo Isaza Report

0

<td> { assessment.categoryCategory === 'Complete' ? ( <button type="button" className="btn btn-success">Complete</button> ) : ( <button type="button" className="btn btn-info">Not Completed</button> ) } </td>
about 4 years ago · Juan Pablo Isaza Report

0

¿Por qué no simplificarlo así?

 <td> <button type="button" className={assessment.categoryCategory === 'Complete' ? "btn btn-success" : "btn btn-info"}> {assessment.categoryCategory === 'Complete' ? "Complete" : "Not Complete"} </button> </td>
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!