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

125
Vistas
How to set proper styled component for react if statement using React.js

I'm working on my own project by plan "from Zero to Hero" my friend told me about styled components and I've decided to replace my clear .css and move to styled components.

I know how it works in basic. <MyComponent> and than const MyComponent = styled.div css, css, css

Im strugling about these 2 situations

  1. <div className={color ? 'header header-bg' : 'header'}> How to code it for styled components? Like <MyComponent={color ? 'header header-bg' : 'header'}> But than i dont know what else..

  2. In clear styles I have many situations like

    .class1, .class2, .class3 { styles }

How can I write it in styled components, please? For now, I have 3 times the same code for every class1-3, and that's not good. Also i tried something like const Class1, Class2 = styled.div but it doesn't work

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

0

you can pass the props in styled components instead of ternary operators, here the link you can see the example Add background color conditionally in styled components and const Class1, Class2 = styled.div this will not work, you should have do like this

const Class1 = styled.div``
const Class2 = styled.div``
const Class3 = styled.div``

And you should learn about the styled components from this link

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