Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
change color of the badge - condition

I am a beginner at React. I would like to change the color of the badge in dependency to the number of registered students. Something like on the picture. If the item.registeredCount (number of registered students) = (item.capacity - 1) then the color will be red (for example 1/2, 4/5, 10/11, etc) else the color of the badge will be green because the capacity is not half full. In case when the item.capacity = 1, the color of the badge will be green.

My code:

<Col className="text-center">
   <div>
      <Badge 
          bg="danger">{item.registeredCount}  /  {item.capacity}
      </Badge>
   </div>
</Col>

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To solve your problem, you can use the ternary operator (Documentation) to choose your badge's color.

<Badge bg={(item.registeredCount === item.capacity - 1) ? "green" : "danger"}>{item.registeredCount}  /  {item.capacity}
</Badge>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda