Embarking on my latest project with the goal of going "from Zero to Hero", I received a tip from a friend about styled components. Intrigued, I decided to ditch my traditional .css files and make the switch.
Although I understand the basics - using <MyComponent>
followed by const MyComponent = styled.div
with CSS properties in between - I'm facing some challenges.
I'm particularly struggling with these two scenarios:
How do I convert
into styled components format? Can I use something like<div className={color ? 'header header-bg' : 'header'}>
? But then what's next?<MyComponent={color ? 'header header-bg' : 'header'}>
In regular stylesheets, I often group selectors like so:
.class1, .class2, .class3 { styles }
Could someone guide me on how to achieve this with styled components? Currently, I find myself repeating similar code for each class (class1-3) which seems inefficient. I attempted creating variables like
const Class1, Class2 = styled.div
but encountered issues.