What distinctions are there between placing a `<link rel="stylesheet" href=..video.scss>` in the index.html versus utilizing `import '../video.scss'`?

As a newcomer to React.js, I've observed that there are different ways to include stylesheets in a React Component. Some developers use the import method like this:

import '../../styles/video.scss

while others prefer to link the stylesheet directly in the index.html file:

<link rel="stylesheet" href="./css/styles.css">

I'm curious about when to use each method and which one is generally preferred when working with ReactJs?

Answer №1

import '../../styles/video.scss'

This is definitely the way forward.

The main distinction is that importing in this manner will pass through the webpack pipeline, including loaders. The specific loader that transpiles SASS looks for ES6 imports and cannot transpile link tags in the index. In simpler terms, you can't import sass & other similar files using a link tag.

Additionally, continually adding items to the index file will cause it to quickly become cluttered and disorganized.

Furthermore, your scenario only pertains to global css imports, which can be accomplished through a link in the index file. However, modular css requires module imports.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display issue with ul and li elements in Safari browser causing menu to appear incorrectly

Although I am new to CSS, I managed to create a menu on my website that hovers over the background video successfully. It is a basic menu using a ul with li elements and it appears as intended in all browsers except Safari. In Safari, the menu items stack ...

Differentiating Routes in React JS to the Same Path

My website currently has a navigation bar with the following options: Home|Shop|About. However, I am looking to add a link on my Home page that will open the same shop page as the one in the navbar. Is it possible to implement two different routes that le ...

Tips for setting up React-select Async with default selections for modifying an item utilizing a search API

I am currently utilizing React-Select's Async Select feature to create a dropdown menu that allows users to search through a vast amount of data. Users can see employee names as they search and are able to select multiple employees. The data for Reac ...

Utilize an array value as a parameter for getStaticProps within Next.js

Currently, I am fetching my Youtube playlist using a fetch request and utilizing getStaticProps(). However, I am encountering an issue where my playlist is dependent on the result of an array of objects. export async function getStaticProps(){ const MY_P ...

Storing the value in memory by utilizing the useMemo function in conjunction with the useSelector hook

When utilizing the useSelector hook to retrieve a value, I am interested in retaining a mapped version of that value: const selectedValue = useSelector(...); const derivedValue = useMemo(() => selectedValue.map(...), [?]); // What should be included her ...

Different ways to retrieve .env variable in _app.js script

Environment File Information ID=123 In my pages/index.js file, I am successfully able to access the variable by using ${process.env.ID}. However, when attempting to do the same in my _app.js file, it returns as undefined. Can anyone provide guidance on h ...

Adding alpha or opacity to the background image will give it a unique and

Is there a way to darken the background image while keeping the text color the same? Check out this code snippet on JSFiddle div { display:block; background:url('http://placehold.it/500x500') 0 0 no-repeat; background-color:rgba(0 ...

Programmatically simulate a text cursor activation as if the user has physically clicked on the input

I have been attempting to input a value into a text field using JavaScript, similar to the Gmail email input tag. However, I encountered an issue with some fancy animations that are tied to certain events which I am unsure how to trigger, illustrated in th ...

Step-by-step guide on creating a draggable navigation bar:

I am encountering an issue creating a droppable menu. I am currently working on Menu 1 but struggling to figure out how to make the drop-down menus appear on the right side. <link href='http://fonts.googleapis.com/css?family=Oswald:300,400' r ...

The lack of vertical alignment in the table

Trying to do something really simple here and I'm a bit stuck. Currently working on a forum project, and surprisingly the backend is error-free (thanks to some questionable magic tricks), However, my current task is to display all subcategories using ...

Discovering all words enclosed by '#' in a string using React TypeScript

Trying to figure out how to extract words between '#' in a given string... For example: const str = `<Table striped bordered hover> <thead> <tr> <th>#project name#</th> <th>#First Name#& ...

Roundabout Navigation Styles with CSS and jQuery

My goal is to implement a corner circle menu, similar to the one shown in the image below: https://i.stack.imgur.com/zma5U.png This is what I have accomplished so far: $(".menu").click(function(){ $(".menu-items").fadeToggle(); }); html,body{ colo ...

instructions on how to showcase a text message within the fontawesome square icon

Can someone help me with styling my code? I want to display a text message inside a square box with dimensions of 1x. <span class="fa-stack fa-5x" style="margin-left:5%"> <i class="fa fa-square-o fa-stack-2x"></i> </span> ...

Resizing an image within a div with automatic adjustment, centered and aligned to the bottom position

I'm really struggling to understand this concept and not making much progress. I have a background image that automatically scales to fit the window size. In front of it, I want to center an image fixed to the bottom of the page, while still being sca ...

Emphasize the specific dates on the MUI StaticDatePicker calendar

Seeking help with implementing the MUI StaticDatePicker in my React website. I'm looking to highlight specific days on the calendar using a blue circle or badge, but have been unsuccessful so far. If anyone has experience with this, your assistance wo ...

Discover the position of a div relative to another div using ng-drag-drop

I'm currently working on a web application that allows users to create their own identity cards. For this project, I am incorporating the ng-drag-drop library from https://www.npmjs.com/package/ng-drag-drop. The main goal is to obtain the coordinate ...

A comprehensive walkthrough on getting started with your project setup using Cordova, Onsen, and React - from setting up

Are there any comprehensive step-by-step guides available for creating an Onsen UI 2 + React + Redux + Cordova application from the ground up? While there are many resources out there, very few of them cover the initial project setup process: which npm pa ...

There appears to be a malfunction with WebRupee

I have incorporated the new rupee sign into my website to represent Indian currency. Below is the code snippet I used: For the script, I included " and also added the following: <span class="WebRupee">Rs.</span> 116,754.00 To style it using ...

What is the best way to arrange these divs one on top of another?

I have combed through numerous resources but still haven't found a solution to my problem. I am struggling with figuring out how to stack the "top_section" div on top of the "middle_section" div. Currently, "middle_section" is appearing above "top_sec ...

Element remains hidden when position set to relative

I have created a panel inside a container class. The panel's CSS is as follows: .panel { width: 100%; background: url(img/launch1.png); height: 80%; background-size: cover; background-position: center; position: relative; ...