-
Notifications
You must be signed in to change notification settings - Fork 552
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
Access SASS variables from css-module in a React component #86
Comments
Speaking to @geelen we first tried using @value brandSecondary "#{$brand-secondary}"; This worked, but it returned a string of a string FINAL SOLUTION that worked (again on suggestion from Glen) was to use: I am now doing the following, and it works nicely:
@import "~shared/variables/colors";
:export { brandSecondary: $brand-secondary; }
.root {
color: $brand-primary;
}
...
<SomeFooBarComponent takesAColorProperty={styles.brandSecondary} />
... |
This is awesome |
@hadimichael Can you explain how this is working? I would've expected something more like this for
Otherwise when just given a string how does |
@axelson you're totally right! Typo on my behalf, thanks for pointing it out. Edited above. |
Thank you @axelson and @hadimichael
But not sure how to adapt it to my scss files... EDIT: Just made it work with this project https://github.com/nordnet/sass-variable-loader. |
If you don't need all your variables \ install one more loader
|
This totally breaks my HMR too... any way to fix this? |
Thanks for this great solution! let selectedColor = "brandSecondary";
<SomeFooBarComponent takesAColorProperty={styles[selectedColor] /> |
I have a React component that is using css-modules. Is there a way for me to get access to the SASS variables used in the css-module?
My
styles.scss
file is using a shared_colors.scss
file. My files look something like this (note the comment for use-case):index.jsx
shared/variables/_colors.scss
styles.scss
The text was updated successfully, but these errors were encountered: