add sass to react
npm install node-sass --save-dev
add sass to react
npm install node-sass --save-dev
react access scss variables
const appBarElement = document.querySelector('.appBar');
if (appBarElement) {
const style = window.getComputedStyle(appBarElement);
const position = style.getPropertyValue('position');
console.log(position);
}
how to use sass in react without eject
#### Using sass in react without ejecting
#1.First install node-sass
npm i --save-dev node-sass
#2.Then install npm-run-all
npm install --save npm-run-all
#Then change the scripts of package.json:
# "scripts": {
# "build-css": "node-sass src -o src",
# "watch-css": "npm run build-css && node-sass src -o src --watch --recursive",
# "start-js": "react-scripts start",
# "start": "npm-run-all -p watch-css start-js",
# "build": "npm run build-css && react-scripts build",
# "test": "react-scripts test --env=jsdom",
# "eject": "react-scripts eject"
# }
#After that, create a scss file beside each css file with the same name
#then run:
npm start
#after that every time you change the scss files, css files also ill be updated.
# !!! no need to change the imports of css files
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us