-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theming via context in a stateless component throws error. #153
Comments
context
to not come from the closest scope.
@DavidBachmann we don't allow dynamic styles on purpose see this and this. We are planning on adding support for dynamic styles though so stay tuned! :) P.S. the fact that it works with classes is a bug, thanks! I need to fix it :) |
I understand the reason for this check. However, for widget libraries (think Material UI), it makes sense to get theme variables from the context instead of global variables. Consider a Would you consider a PR for an optional babel flag that silences this error? For projects/libraries that "know better". Something like: {
"plugins": [
["styled-jsx/babel", {
"scopeCheck": false,
}]
]
} Or maybe there could be another attribute/value like #81 that disables this check? |
Thanks for clearing this up @giuseppeg. I second @eirikurn's proposal, though. |
Probably although I think that we should implement #81, what do you think @rauchg ? Keep in mind that as soon as you have a dynamic prop, two themes or a component is used with and without theme this would break because styles are not hashed at runtime and are deduped based on that hash no matter what is their final value. eg. const Button = ({children}, {theme = {primary: 'gray'}}) => (
<button>
{children}
<style jsx>{`
button { background-color: ${theme.primary} }
`}</style>
</button>
)
// later ...
<button>howdy</button>
<ImaginaryThemeProvider theme={{primary: 'blue'}}>
<button>howdy</button>
</ImaginaryThemeProvider> |
this will be possible when we add support for dynamic styles #81 |
Theming via context in a stateless component throws the following error:
Here's an example of what I'm trying to do:
Turning the component into a class works, but I would really appreciate having my stateless components theme-able.
Is this a bug, a missing feature, or am I missing something?
Thanks
The text was updated successfully, but these errors were encountered: