Utilizing kebab-case conventions for CSS class names in CSS/SASS modules within a Next.js environment

Currently, I am utilizing SCSS modules to style my components in React/Next.js but I can't seem to grasp how to import kebab-case classes.

As of now, I find myself writing all my SCSS classes in camelCase format, which is not the most efficient approach as it restricts me from taking advantage of SCSS cascading features.

(I am still in the learning phase with React and struggling with creating dynamic components on my own, so I rely on React Strap for assistance at the moment.)

Essentially, what I desire is to write:

.company-logo

rather than:

.companyLogo

EDIT:

className={styles['company-logo']}
triggers an unexpected token error

This is my Component:

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

const NavComponent = (props) => {
  const [isOpen, setIsOpen] = useState(false);

  const toggle = () => setIsOpen(!isOpen);

  return (
    <div>
      <img src="../ss-logo.png" alt="Logo" className={styles.companyLogo}/>
    </div>
  );
}

export default NavComponent;

And here is my SCSS:

.companyLogo {
  height: 3rem;
}

Answer №1

className={styles['company-logo']}

That is the desired outcome.

Answer №2

Utilize the square bracket notation for object keys.

<img src="..." className={styles['company-logo']}`

Answer №3

<img src="../ss-logo.png" alt="Logo" className={`${style['company-logo']}`}/>

Answer №4

Code Snippets:

<img src="../ss-logo.png" alt="Logo" className={`${styles["company-logo"]}`}/>

Using Variables:

var logo = classNames({
  [`${styles["company-logo"]}`]: true,
});

return (
  <div>
    <img src="../ss-logo.png" alt="Logo" className={logo} />
  </div>
)

Answer №5

Absolutely, although it's worth noting that without autocomplete and the ability to jump to definitions, I'm simply using camelCase for naming conventions in my module.css file :)

Answer №6

To access an object with a dash separator, you can utilize the bracket notation []:

<img className={styles['company-logo']}/>

For applying multiple class names, template literals can be used:

<img className={`${styles['company-logo']} ${styles['personal-logo']}`/>

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

Tips for assigning a unique button and checkbox to each item in an ng-repeat list

I am currently working on a ToDo-List exercise in JavaScript and have chosen to utilize AngularJS in order to enhance my skills. Check out the Github repository here In my initial attempt, I have set up two unordered lists - one for active items and anot ...

Does this task require a high amount of CPU resources for Node.js on the back-end?

I am currently developing an Android app and I am faced with a decision on whether to utilize node.js or PHP for the back-end. The task at hand involves users inputting query parameters, such as zip codes, which are then used to perform database queries ...

Updating FieldArray elements with Redux store variable can be done by following these steps:

I'm currently utilizing redux-form with a FieldArray. By default, the array contains 1 element that is populated from JSON. The FieldArray component allows me to add up to 3 elements. In the code below, the 'elementList' property is sourced ...

Displaying various results using a range slider

I really need some assistance in making this range slider produce multiple outputs. I've attempted a few different options, but unfortunately, I haven't been able to figure it out. My goal is to have the text "590" display as 5.9 times the value ...

The Ajax request is encountering an error while trying to access the file

I am facing an issue with my website that has two pages - a process page and a form page. The form page contains multiple input fields, and when the user submits the form, it triggers an AJAX call to the process page. The process page requires the user&ap ...

How to align button text and other ion-col text at the bottom in Ionic 2

Here is the code snippet I am working with: <ion-row><ion-col ><button ion-button outline no-padding large (click)="setUserName()">D</button>ay in the life </ion-col></ion-row> I find the layout unattractive as the le ...

Adjusting the transparency of numerous elements using JavaScript or jQuery

My task involves creating a large form where elements initially have an opacity of 0.5, and when a button is clicked, the opacity changes to 1.0. While I can achieve this using JavaScript, I want to find a more efficient way by avoiding individual if state ...

Optimal approach for integrating an ionic mobile app with Django to streamline form processing

Currently in the process of developing a mobile application with ionic technology. In the case of a traditional django website, we typically create context within the view and pass it to the template, where the HTML is displayed using various methods such ...

Diverse browser behavior regarding HTML5 table cell padding

This situation can be simplified for better understanding. What I am observing is a discrepancy in appearance between Chrome 7.0 and Firefox 3.6.12. Interestingly, IE 9 beta seems to resemble Chrome. My goal is to apply padding to the TD element and have ...

When a checkbox is selected, new input fields will dynamically appear

I have a table with 3 text fields and I would like to dynamically add the same set of text fields when a checkbox is clicked. Below is the code snippet I have, how can I achieve this using PHP and JavaScript? echo "<td>Screen ".$i."</td>"; ...

What are the steps for configuring i18n translated URL paths in Next.js?

I have successfully implemented multi-language support on my website using Next.js i18n-routing. When I create a file in /pages/about.js, the URLs are generated based on my locale settings: EN -> /about DE -> /de/about ES -> /es/about Everything ...

Execute the file separately using dot.js

When working on my project, I decided to include a header.def file in index.dot by using the {{#def.header}} snippet. To render the index.dot file, I utilized the following snippet: var dotjs = require('dot'); var dots = dotjs.process({ path: ". ...

Mastering intricate string manipulation using JavaScript regular expressions

I have a JavaScript/Node JS program that generates meaningful names according to the following rule: Input: "tenancy_account__accountPublicId__workspace__workspacePublicId__remove-user__userPublicId" Expected output: "TenancyAccountAcco ...

How can I determine when a WebSocket connection is closed after a user exits the browser?

Incorporating HTML5 websocket and nodejs in my project has allowed me to develop a basic chat function. Thus far, everything is functioning as expected. However, I am faced with the challenge of determining how to identify if connected users have lost th ...

Displaying placeholder text instead of actual input value

I need help figuring out how to make the input field display the placeholder text instead of the initial value from state. const initialState = [ { name: "Chris", age: 0, height: 0, weight: 0, }, ]; const [inf ...

Retrieve Cookie from a designated domain using Express

I am currently working on a React application that communicates with a Node/Express backend. To ensure the validity of requests, I am sending a cookie created by react-cookie from the React app to the Express app. To avoid issues related to naming conflict ...

Improving the layout of text by adjusting the width within a flex-box styled card

I have a card with the style property "display: flex;" applied to it along with other stylings, all of which are checked in the snippet below. My goal is for the text within the card to move to a new line once its width reaches either 120px or 7 ...

Enhancing react-confirm-alert: Steps to incorporate your personalized CSS for customizing default settings

I'm currently utilizing a confirmation popup feature provided by react-confirm-alert: popup = _id => { confirmAlert({ title: "Delete user", message: "Are you sure?", buttons: [ { label: ...

Utilize the hexadecimal color code as a string within the darken function

When working with a less style, I have a string variable. @colorString: 'DADADA'; I can convert it into a color: @color: ~'#@{colorString}'; Then, I am able to use @color to define a value in a style: div { color: @color } However ...

enhancing the style of my Express project with CSS and EJS

Currently, I am facing challenges with linking CSS to my EJS files in a project I am developing using Node/Express/EJS. Despite creating a public folder with a CSS subfolder and the main.css file inside, I am unable to get the CSS to display in the browser ...