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

196
Vistas
How can we pass a color as a prop?

I have a component which has the color white if it is active and black if it is inactive. How can a pass the color black as a prop?

My code right now (it does nothing):

export function Card (props) {
  return <div {...props} className={styles.gray} />
}

I want to use this component (called Card) in a ternary operator to show if the component is active or not.

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

0

Assuming that you are setting the active state outside of the card, here's the simple ternary pattern.

If active is defined outside of the card:

function Card({ isActive, ...props }) {
  return (
    <div
      className={`${styles.gray} ${isActive ? styles.active : null}`}
      {...props}
    />
  )
}

Using a helper like clsx, it would look like:

<div className={
  clsx(
    styles.gray,
    isActive ? styles.active : null,
  )
} />
about 4 years ago · Juan Pablo Isaza Denunciar

0

Is styles the name of your css style sheet and gray the selector?

There are a bunch of different ways to create this behavior, but an easy one if you have a props object with color as a prop, you can do: <div style={{ color: props.color }}

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