question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@emotion/react: Support using theme props with `css` API

See original GitHub issue

The problem

Existing css from @emotion/react doesn’t support accessing theme props as such:

const mixin = css`
  color: ${props => props.theme.colors.primary}
`'

Proposed solution

Please support it as it is helpful for React developers:

  • Allow use cases in theme definitions, mixins, helpers, etc. where accessing theme props is required
  • Users migrating to Emotion from Styled Components will be blocked by the lack of this feature

No specific solution from me but styled-components is a good example.

Alternative solutions

N/A

Additional context

Similar issue: #801

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Andaristcommented, Mar 9, 2021

You can also just refactor this to:

const mixin = theme => css`
  color: ${theme.colors.primary}
`'
2reactions
linxianxicommented, Jun 7, 2021

@StevenVerbiest I’m not sure if I understand the improvement your suggesting. Maybe you can elaborate a bit on it. When you use solution 3 in the sandbox the CSS API is able to use the custom theme without us having to pass it. The type declaration is there just to make typescript happy. Due to how typescript is typed I think there is no way to get rid of this type of definition.

I think the improvement your looking for is similar to what I asked in #2291. After a discussion with @Andarist, I however agree that the module declaration overload is currently the cleanest solution we can support.

It would be nice if solution 2 didn’t have to write the type every time. Style-component library can be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theming - Emotion
Theming is included in the @emotion/react package. Add ThemeProvider to the top level of your app and access the theme with props.theme in...
Read more >
How To Use Emotion for Styling in React | DigitalOcean
emotion provides a css prop that can accept nested selectors and media queries. It can support an object or a tagged template literal....
Read more >
Reactjs — Emotion For Styling Components | by Avery Duffin
We can access theme anywhere within styled components or by using withTheme. After that the theme is just another prop passed into the...
Read more >
Emotion in React - LogRocket Blog
Emotion is a high performance, flexible, and performant CSS-in-JS library. Emotion helps us to style our application in a faster way, with a ......
Read more >
Accessing Material UI Theme Object in Emotion JS
Pass the Material UI Theme Object to Emotion's ThemeProvider · Emotion Styled Components - Access Theme from props · Emotion CSS String Styles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found