Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem in accessing the scss variables in react components

Tags:

sass

reactjs

icss

Followed the link https://mattferderer.com/use-sass-variables-in-typescript-and-javascript

Looking to access the scss varaibles in react component . Not sure with what import name i need to call in react component since if i give as below import statement it is showing an error as cannot find the module '../scss/_variables.scss';

import _variables from '../scss/_variables.scss';

here _variables.scss is the file name which contains

 // variables.scss
$white-color: #fcf5ed; 

:export {
  whitecolor: $white-color; }

I am scratching my head to get the "whitecolor" variable available in react component .

Also, I am using webpack as below

{
 test: '/.scss$/',
 use: [{
  loader: 'style-loader' // creates style nodes from JS strings
 }, {
  loader: 'css-loader' // translates CSS into CommonJS
 }, {
  loader: 'sass-loader' // compiles Sass to CSS
 }]
}

enter image description here

Any help would be highly appreciated!!

like image 214
Srinu Merugu Avatar asked Dec 22 '22 22:12

Srinu Merugu


1 Answers

Importing specific property in React does not work unless it is a module.

I was facing the same problem and here is what I did:

Renamed _variables.scss to _variables.module.scss and then the import is import _variables from '../scss/_variables.module.scss';

now you can access the scss variables just like _variables.whitecolor

like image 82
Yatin Gaikwad Avatar answered Mar 06 '23 11:03

Yatin Gaikwad