How to use sass stylesheet in react app

How to use sass stylesheet in react app

In this post we will give you information about How to use sass stylesheet in react app. Hear we will give you detail about How to use sass stylesheet in react appAnd how to use it also give you demo for it if it is necessary.

we are going to learn about how to add and use sass(syntactically awesome style sheets) to your create react app with the help of an example.

What is Sass?

  • Sass is a css preprocessor, which allows us to use features that don’t exist in CSS like nesting, mixins, inheritance, etc.

  • Sass compiler complies your sass files into css files.

Adding sass to react

To use sass in react we need to install a new package called node-sass from the npm.

This tutorial assumes that you already created a new react project using create-react-app cli.

Run the below command to install node-sass.

npm i node-sass

Now, we are ready to use sass in our react app without ejecting.

Using sass

Now, rename your .css files into .scss and also change your css imports to scss.

Example:

index.scss
$font-stack: Helvetica, sans-serif;$primary-color: #333;body {  font: 100% $font-stack;  color: $primary-color;}
index.js
import React from 'react';import ReactDOM from 'react-dom';import './index.scss';import App from './App';ReactDOM.render(<App />, document.getElementById('root'));

Hope this code and post will helped you for implement How to use sass stylesheet in react app. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US