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

143
Vistas
Change the color of a card while mapping through an array based on it's value in react?

I want to change the color of the card based on the value of the current slot which is an object in an array. So when I am mapping through a card I want to change the backgroundColor of the card based on the value. How should I do that? My current approach doesn't seem to work.

slots.map(slot => 
          <Card key ={slot._id} style={{backgroundColor:slot.OccupiedStatus?'black':'teal'}}>
            
            <Typography>{slot.category}</Typography>
          </Card>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since The Card is a React Component, in your case the style is not considered an attribute instead it is a prop that will be passed on to the Card component.

You can catch that style prop in your Card Component and use it.

const Card = (style, ...otherProps) => {
    return <div style={style} >hello</div>
}
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