Using SCSS to apply a class in Next.js

Currently, I am working on a project using Next.js and implementing the SCSS module procedure for styling.

An example component directory structure is as follows: SampleComponent -> index.tsx and SampleComponent.module.scss

The code in SampleComponent.module.scss:

.box {
    // Some CSS (let's call it set1)
    &.disabled {
        // Other CSS (let's call it set2)
    }
}

In the index.tsx file:

import styles from './SampleComponent.module.scss'

<div className={styles.box}></div>

How can I incorporate the disabled class here?

Thank you in advance!

Answer №1

If you're looking to apply both the 'box' and 'disabled' classes to your div element, there are a couple of ways to achieve this. One option is to use template literals like so:

<div className={`${styles.box} ${styles.disabled}`}></div>

Alternatively, you can concatenate both classes into a single string variable:

let classes = styles.box + ' ' + styles.disabled

And then apply it to your div element like this:

<div className={classes}></div>

Answer №2

If you're looking to simplify your CSS classes, consider using the classnames package. Check out the classnames package here

<div className={classNames(styles.box, styles.disabled)}></div>

Alternatively, you can achieve the same result by combining classes like this:

<div className={`${styles.box} ${styles.disabled}`}></div>

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

ReactJS encountered an error: Module '@progress/kendo-scheduler-react-wrapper' could not be located

![kendo ui npm issue]https://i.stack.imgur.com/5cERD.jpg Struggling with a 'can't resolve' error when attempting to integrate this kendo-ui package. ...

tips for efficiently using keyboard to navigate through tabs in an unordered list

Utilizing unordered lists in this web application. I am looking to implement tab navigation with keyboard functionality. How can I achieve this? The first tab should contain text boxes, and when the user fills out a text box and presses the tab key, they s ...

What is the best method to update numerous low-resolution image sources with higher resolution images once they have finished loading?

I'm currently developing a website that implements a strategy of loading low-resolution images first, and then swapping them for high-resolution versions once they are fully loaded. By doing this, we aim to speed up the initial loading time by display ...

Utilizing Node.js within a closed intranet environment

Utilizing Nodejs's npm has proven to be quite convenient. Thus, I made the decision to incorporate it into my company's project. However, a predicament arises as my company mandates development within a closed network. This restricts my access s ...

Tips on deleting excess space in between Material-UI Grid Rows

https://i.stack.imgur.com/nASqM.pngWhen attempting to utilize the Material UI grid system, I encountered an odd spacing issue when using grid direction='row'.https://i.stack.imgur.com/sl59V.png const useStyles = makeStyles((theme) = ...

Navigating out of a Modal in React: A step-by-step guide

I have a button on the initial page of my web application. When this button is clicked, a modal form pops up. Upon submitting this form, an API call is made to update the database with no response expected as it's a one-time entry. As this is the sta ...

What is the best method to remove the gap between my two horizontal div elements?

Is there a way to eliminate the small space between my two horizontal sections here? I've already attempted using margin: 0px; and padding: 0px; on the container, but it doesn't seem to be effective. Any assistance would be greatly appreciated! ...

Creating a custom progress bar using Javascript and Jquery

I developed a progress bar that is fully functional. Here is the HTML structure: <div class="progress"> <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style ...

What is the reason for next.js to execute getStaticPaths each time a page is loaded?

During the pre-rendering of my product detail pages, I encountered an issue with Next.js where the getStaticPaths function was being called on every page refresh or URL change even if it was the same page. This caused a delay and made the page unresponsive ...

Creating a container component that has access to the values of its children: a step-by-step guide

I've designed a component wrapper that looks like this: <SpecialWrapper config={}> {this.props.children} </SpecialWrapper> The intention is to utilize it in the following manner: <SpecialWrapper> // whatever other c ...

Is it possible to showcase a close symbol and a checkmark symbol simultaneously within a material ui chip component?

Material ui chip component documentation typically shows either a close icon or a done icon individually. Is there a way to have both displayed at the same time? <Chip label="name" onDelete={handleDelete} /> I attempted add ...

Angular not updating the values in real time

First and foremost, I am utilizing socket.io to emit data. Data is emitted upon connection (so the website does not appear blank) as well as when certain events occur. Upon initial connection or page refresh, everything updates and functions smoothly. Howe ...

Creating a column heading that appears at the top of each column break with the help of CSS column-count

Is there a way to output a list into x number of columns within a content div without specifying the exact amount of columns in CSS? I also want to include a heading at the top of each column: Firstname Lastname State Firstname Lastname State ...

Try utilizing an image to hold text content rather than a traditional div container

I am seeking help with displaying a brief image description at the bottom of an image. Currently, the display looks like this: https://www.bootply.com/render/Gwde8WHtot However, I would like the green background to align with the actual image rather than ...

Mastering the art of seamless navigation within a single page through the magic of

I have two HTML pages: "Login.html" and "index.html". Instead of a normal href linking, I want the user to navigate to "index.html" when they click on the login button. Furthermore, I want the index page to be displayed within the codes of login.html, cre ...

Issue with Backbone collection not being updated despite making a JSONP request

Recently, I delved into the world of Backbone.js and currently, I am immersed in developing an app using Brunch that makes a JSONP request to an external API for populating my collection and models. Despite following guidance from previous posts (here and ...

Transferring a JavaScript variable to PHP using Ajax within the same webpage

Check out my HTML and JavaScript code: <form id="form" action="javascript:void(0)"> <input type="submit" id="submit-reg" value="Register" class="submit button" onclick="showtemplate('anniversary')" style='font-family: georgia;font- ...

A guide to adjusting the width without affecting the td element

Currently, I am facing a challenge while coding in HTML. I am trying to create a table with a header (time range) that fits on a single line without affecting the width of the td elements. Below is the code snippet: <table style="border:1px solid #8c ...

Troubleshooting: Why is the Kendo React TreeView CheckBox malfunctioning

Having Trouble Checking CheckBoxes within TreeView Component https://i.stack.imgur.com/QpFjq.png Here is the code snippet for a Treeview component with CheckBox nodes inside an expansion panel: <ExpansionPanel className='item-body-dropD ...

Incorporating an NPM module into a React file: Webpack encounters resolution issues

After reviewing information from this source and here, the process of publishing a react module to NPM and then using it in another project while having the component in the node_modules directory should be as follows: Create and export a module Specify ...