[Question] Passing classes from parent component
See original GitHub issueHi
I migrated to Emotion from Glamorous and I miss one thing (or maybe I just don’t know how to do it). It’s connected to this: https://emotion.sh/docs/class-names, but I don’t think it’s actually good developer experience.
What I do is writing self-contained components, which are basically not positioned (no margins, sizes etc) and positioning happens in parent, which layout them.
To achieve that, there are two ways to do this: 1: Wrapper:
<div className="layout">
<div className="layout__nav">
<NavComponent />
</div>
<div />
This more-or-less works, but has some limitations, also required extra markup
2: Mix classes
<div className="layout">
<NavComponent className="layout__nav" />
<div />
This is preferable to me, my component looks like this then:
const NavComponent = ({...props}) => (<SomeEmotionStyled {...props}>...</SomeEmotionStyled>)
This worked in Glamorous. I’ve seen in <ClassNames>
HOC this can be achievable, but it’s a lot of extra code, when I use it quite often.
What is desirable approach here? css
function doesn’t return css class, so it’s not easy to pass it down
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Hopefully, everyone engaged in this conversation has resolved their issue. If not please open a new one.
I mostly work with Emotion 9, but also work with Emotion 10. Here is an example of what I do :