Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!