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

What is the best way to transform private variables in ReactJS into TypeScript?

During my conversion of ReactJS code to TypeScript, I encountered a scenario where private variables were being declared in the React code. However, when I converted the .jsx file to .tsx, I started receiving errors like: Property '_element' d ...

Vuetify displaying incorrectly following deployment

After creating a spa with vue.js for the frontend, I utilized the vuetify library for various components and layout. While everything looked great locally, upon deploying to Azure, all vuetify styling seemed to disappear. My custom css was still applying ...

The text-decoration is here to stay

Currently, I am facing an issue with the customization of a wordpress theme related to the styling of links within posts. Although I have tried to change the color and remove underlining using CSS rules, I am unsuccessful so far: a, .entry-meta a, entry-c ...

What is the reason that elements with % properties totaling 100% do not align next to each other?

I've been attempting to arrange two blocks side by side within another block, but they just don't seem to fit together smoothly. What could be causing this issue? .container {height: 200px; width: 400px; background:darkgrey;} .left {height: 100% ...

Encountering a CORS error in my Next.js 13.4 application while attempting to retrieve JSON data

Here is the location of the actual fetch request in our search/page. import { useSearchParams } from "next/navigation"; import Footer from "../components/Footers"; import Header from "../components/header"; import { format } ...

Is there a way to position a ListItem (using React) in the lower left corner in this specific case?

import * as React from 'react'; import { styled, useTheme } from '@mui/material/styles'; import Box from '@mui/material/Box'; import MuiDrawer from '@mui/material/Drawer'; import MuiAppBar from '@mui/material/Ap ...

I am having trouble getting my CSS styles to apply to nested components within Bootstrap React components

Currently I am learning react and in the process of creating a website using react-bootstrap. While working on my navbar, I encountered an issue where I was unable to change the font and font-color of the navbar items. The CSS that I applied only affected ...

React callbacks involve the interaction between three different components

Currently, I am working with 3 distinct components: -The friendsPage component contains a list of friends and invitations to friends -The friendComponent displays detailed information about a friend along with possible actions (which are handled in the t ...

Encountering the message 'Required "key" prop missing for element in array react/jsx-key' during the build process

Encountering an error message while deploying my Next.js app on Vercel. If you'd like to take a look at the code, it's available on GitHub. During the deployment process, I'm receiving the following error: "Missing "key" prop for element ...

An issue has occurred in React Native with the error message stating that `(0, _reactNativeCodePush2.default)` is not

Currently working on a React Native project and I encountered an error when trying to run it. Can anyone provide guidance on how to resolve this issue? ...

Encountering a problem with npm during the installation of a package in a

Every time I attempt to install an npm package, I encounter a particular error message that causes the installation process to come to a halt. Below is the exact error message: Error Message: This npm version is designed for lockfileVersion@1, however, ...

javascript include new attribute adjustment

I am working with this JavaScript code snippet: <script> $('.tile').on('click', function () { $(".tile").addClass("flipOutX"); setTimeout(function(){ $(".tile-group.main").css({ marginLeft:"-40px", widt ...

The issue with Docker compose is that React JS does not refresh as expected

Being new to dockers and everything related to it, I have been struggling with getting my FrontEnd code changes to update in my docker-compose project. Despite trying tutorials and instructions from the web, the answers from this question point me towards ...

Encountering an issue: When using .NET Core with React and NextJS, receiving a TypeError stating that _interop_require_default._ is not

Working on a new project in .NET Core with SPA using React. Want to incorporate nextJs for some navigation features. Encountering this compile error: Compile Error The error points to app-router-context.shared-runtime.js and specifically mentions the fo ...

How can I resize an element using jQuery resizable and then revert it back to its original size with a button click?

I need help figuring out how to revert an element back to its original size after it has been modified with .resizable. I attempted the following: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//code. ...

Incorporating ScrollMagic and GSAP into Next.js: A Step-by-Step

A project built with Next.js includes the following component: import React, { PureComponent } from "react"; import { Power3, TimelineMax } from "gsap"; import ScrollMagic from "scrollmagic"; export default class TextFade extends PureComp ...

Center the span in CSS by setting its position to absolute

I am trying to create a span element positioned as absolute inside a div. The div has top and left values set. When the user inputs text, the span expands with the given text towards the right to contain it. However, I would like it to grow symmetrically o ...

Error: inability to execute performanceMeasurement.startMeasurement due to its absence in the function definition

An error occurred when attempting to login using @azure/msal-react in Next 13. Upon checking the error log, it was found that the error originated from the core library @azure/msal-react. Even after trying with a login popup, the error persisted. In my co ...

I am facing difficulty importing emotion js style using dynamic variables

I recently designed a webpage that has the following appearance: https://i.stack.imgur.com/AnIXl.jpg Here is the code from my _app.tsx file: import '../styles/globals.css' import type { AppProps } from 'next/app' import { createTheme ...

I'm attempting to integrate the map function into my React Redux application, but after implementing useDispatch, I'm encountering an error message in the console

I am currently troubleshooting an app I'm working on, but I keep encountering errors in the console. Included below is a picture of the error as well as the code snippet triggering the issue. Can anyone provide insight into what might be causing this ...