Update the class name by utilizing template literals

I'm currently in the process of mastering template literals as I have a project where I need to utilize them. However, I seem to be encountering an issue that I can't quite figure out.

Here is the code that is currently working:

const classes = props.classes;

return (
<List
  component="div"
  data-testid="SelectionListt"

  className={classes.selectionList__sites}
>

</List>
);

The question I have is how can I convert the className using template literals?

This is my attempted solution:

 const classes = props.classes;

  return (
    <List
      component="div"
      data-testid="SelectionListt"
       className={` ${classes + ".selectionList__sites"} `}`
     
    >
    
    </List>
  );

Here is my selectionList__sites styling:

 selectionList__sites: {
      backgroundColor: "white",
      "&:hover": {
        backgroundColor: "red",
        color: "black",
        border: "1px solid yellow",
      },
    },

English is not my native language, so there may be some errors in my writing.

Answer №1

Template literals eliminate the necessity for traditional quotation marks within them. Basically, everything enclosed between backticks is treated as a string, except for any values inside ${}.

If we make the assumption that props.classes is a string, then the suggested way to write your className would be:

className={`${classes}.selectionList__sites`}

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 integrate asynchronous computed observable with several concurrent $.ajax requests?

I'm currently working on implementing an asynchronous computed observable following the guide provided here. While I have successfully achieved this for a single ajax call, I am facing a challenge in figuring out how to perform multiple ajax calls in ...

Using ngrx to automatically update data upon subscription

Background The technology stack I am using for my application includes Angular 4.x, ngrx 4.x, and rxjs 5.4.x. Data is retrieved from a websocket as well as a RESTful API in order to share it between multiple components through ngrx. Currently, data is ref ...

What is the best way to update just the image path in the source using jQuery?

I am currently working on implementing a dark mode function for my website, and I have successfully adjusted the divs and other elements. However, I am facing an issue with changing the paths of images. In order to enable dark mode, I have created two sep ...

Enhancing SVG graphics dynamically with JavaScript and ensuring compatibility across different web browsers

I am currently working on incorporating an element into an existing SVG file. Interestingly, the process runs smoothly on Chrome and Firefox but encounters issues on Edge. I aim for it to function seamlessly on the latest versions of all three browsers, wi ...

Rapidly generate VueJS templates for quick display

Is there a way, similar to KnockoutJS, to easily render content from a template using an ID? <script type="text/html" id="template-example"><span>Hello world!</span></script> <div data-bind="template: &a ...

Issue with Tanstack React Query failing to import

Attempting to integrate tanstack react query into my current project to handle state management has proven challenging. Following a tutorial on using react query with nextjs 13, I thought I was following it correctly. However, I encountered various import ...

Customize the MUI Theme to exclusively manage the style of <TextField color="primary"/> component

I am seeking to create a <TextField color='primary'/> with a customized global style. Instead of using styled-components, I believe applying the style in MUI theme provides better control. My query is how can I apply the style exclusively ...

When first accessing the page, the map may not load properly. However, a simple refresh of the page in VueJS should resolve this issue and allow the

After initially loading the page, the map may not work properly in Vue.js. However, refreshing the page fixes this issue. Can anyone provide assistance with this problem? Here is the relevant code: mounted() { this.geolocate(); }, methods: { ...

What steps can be taken to deter users from repeatedly liking comments, similar to the systems seen on Facebook or YouTube for like/dislike features?

I am currently working with express, react, and MySQL. My goal is to implement a like/dislike system for comments. After doing some research, I found that many suggest disabling the like button after a single click. However, I want users to be able to se ...

Tips for utilizing Angular Js to redirect a webpage

Can someone help me figure out how to redirect to another page using Angular Js? I've searched through various questions here but haven't found a successful answer. This is the code I'm currently working with: var app = angular.module(&ap ...

Is commenting required? Well, meteor!

I am currently developing a chat application using Meteor and I am facing an issue where I want to require users to type something before sending a message (to prevent spamming by hitting enter multiple times). Unfortunately, I am unsure of how to achieve ...

Guide to increasing a local storage item's value by 1 upon refreshing the browser in a React application

I have a requirement in my React app where I need to increment the value of the count by 1 every time the browser is refreshed, and also have this count stored in localStorage. How can I achieve this in a proper way using React useState and useEffect hooks ...

Unable to forward with POST request in Node.js

I have a button on the front end that allows users to update their profile photo using the Cloudinary API. When the button is clicked, a Node.js POST request is sent with the user's data to query the database and update the profile photo URL. The func ...

Adding an object to an array using the Array.push() method deposits an array

Currently, I am extracting the days of absence of my colleague from excel files and storing them in a MongoDB database using Mongoose and Express.js. The process of reading the data is smooth; however, when trying to update the data in the database, an un ...

Prevent left click on HTML canvas and enable right click to pass through with pointer-events

In my scenario, I have an HTML canvas positioned above various other HTML elements that detect right-click mouse events. The goal is to be able to draw on the canvas with the left mouse button while simultaneously interacting with the underlying HTML eleme ...

Display information based on the radio button chosen

I've set up a radio button with options for "no" and "yes", but neither is selected by default. Here's what I'm trying to achieve: If someone selects "no", nothing should happen. However, if they select "yes", then a message saying "hello w ...

Is it false to say that false in Javascript is still false?

After conducting some research, it appears that the question I have in mind has not been asked before, or maybe it has slipped under my radar. A rational approach would be to consider the following logic: false && false === true false && true === false t ...

Guide on capturing JSON objects when the server and client are both running on the same system

I created an HTML page with a form that triggers JavaScript when submitted using the following event handler: onClick = operation(this.form) The JavaScript code is: function operation(x) { //url:"C:\Users\jhamb\Desktop\assignmen ...

React error: The type specified is invalid - was expecting a string but received an object instead

Currently, I am encountering an issue in a react project. I am utilizing the rc-upload package for file uploads in react. The code snippet is as follows: import React, { Component } from 'react'; import logo from './logo.svg'; import & ...

Trouble with Adding and Showing Arrays

function resetValues() { var p = parseFloat($("#IA").val()); var q = parseFloat($("#IB").val()); var m = parseFloat($("#CGCD").val()); var aR = []; aR.push("GCD(" + p + "," + q + ")=" + m); document.getElementById("PGCD").innerHTM ...