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

126
Vistas
Passing props.color on inline style - React

I'm trying to pass a color to my text, but it's not applying. If I change to Card.props.color, it works, but the parameter props is never read.

const Card = (props) => {
    return (
        <div>
           <p style={{color: props.color}}>Random text</p> 
        </div>
    )
}

Card.props = {
    color: 'blue'
}


export default Card
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

you should not write this code as this is mutating the props object that react use.

Card.props = {color : 'blue'}

for proper usage the props are passed where you would be using the Card component

<Card color=  {"blue"} />
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can set the default props

const Card = (props) => {
    return (
        <div>
           <p style={{color: props.color}}>Random text</p> 
        </div>
    )
}

Card.defaultProps = {
    color: 'blue'
}


export default Card
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can assign your default prop values to the defaultProps property or even better take advantage of the default function parameters since your component is a function.

const Card = ({ color = 'blue' }) => {
  return (
    <div>
      <p style={{ color }}>Random text</p> 
    </div>
  )
}

export default Card;
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