How to apply CSS styles to a variable containing an element in React

I'm having some trouble styling this element I created. So, I made a variable called test and assigned it to an element.

var test = <Button className="testButton" />

Then in my return statement, I am using the test variable like so:

render () {
var test = <Button className="testButton" />
  return{
    {test}
  }
}

I've attempted to style the button by adding a className, but it doesn't seem to be working as expected. Does anyone have any suggestions on how I can achieve this?

Answer №1

Is that button being generated by Material-UI or something else?

There is definitely a connection with Material-UI here. It seems like the Button is receiving the class testButton and styling associated with it. However, Material-UI Buttons typically inherit styles from inline-styles set by MUI-Theme.

According to the Material-UI website:

All Material-UI components have their styles defined inline.

Essentially, if your class has non-!important styles, they may be overridden by the inline styles. There are a few ways to address this issue:

  • Modify the MUI theme
  • Override the inline-styles
  • Add !important to class styles for overriding purposes

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

Exploring HTML5 video playback in AngularJS

When I use this code: <video id="video" class="video-js vjs-default-skin" controls width="640" height="264"> <source src="http://localhost:3000/files/public/photos/Let-her-go.mp4" type='video/mp4' /> <p class="v ...

New Relic identifies mysterious delays caused by MongoDB's findOne method

After setting up newrelic to pinpoint the bottlenecks in my app, I discovered a major issue that has left me stumped. The source of most delays seems to be mongoDB user.findOne, but the biggest challenge is locating where in the code this delay is occurri ...

Tips for effectively injecting retrieved API response data into a Table

Creating a google-map with customized markers that are logos of companies is the goal. Obtaining a json file from the APIs containing the vessels of interest has been successful. The challenge faced is injecting these vessels into a table on the user inte ...

What is the best way to adjust the CSS height of an HTML select element to 100% within a table cell in Internet Explorer

Is it possible to make a select (dropdown list) element fill out 100% of the table cell height? I was successful in getting it to work in Firefox and Chrome, but unfortunately not in IE (Internet Explorer). Here is the test HTML code: <table> & ...

Placeholder disappears when text color is changed

I have been struggling for 3 hours trying to change the placeholder color to graytext, but it's just not working. Here is the code I've been using: <div class="form-group"> <label for="email">Email:</label ...

Guide on aligning text along a baseline

CLICK HERE TO ENTER THE INTERACTIVE PLAYGROUND HTML: <div class="first">Text A</div> <div class="second">Text B</div> CSS: div { background-color: rgba(255, 0, 0, 0.3); /* For visualization only */ margin-top: 50px; ...

Adding points to a bar or pie chart in a Vue environment can be achieved dynamically by utilizing Vue's reactivity system

Looking to bootstrap a Highcharts bar chart and dynamically add points to it within a Vue container, the documentation references addPoint(), setData(), and update(). However, I struggled to make any of these methods work. The provided demo for updating a ...

Ways to retrieve multiple outcomes in mongoose and merge them into a unified response

When making an API call in Node.js using Mongoose, I want to execute 3 different queries and then combine the results to create a JSON response. Query student .countDocuments({}) .then(studentNumber => { return studentNumber; }) teacher . ...

retrieve the complete webpage content, encompassing the .html file, images, .js files, css stylesheets, and more

I'm currently working on a project and could use some assistance. Is there a method available to download an entire page, including the .html file, images, .js files, css, etc., using PHP, JavaScript, or AJAX? <html> <body> & ...

Changing the shading of an arc in d3.js: Tips and tricks

I've been attempting to create a gauge with a needle that changes the background color of the ring for the past few days. My goal is to dynamically update the colors of an arc within a gauge I developed in d3.js This is my current gauge setup with t ...

Ways to update the color of text exceeding the block boundaries: JavaScript and CSS

When dealing with background images and white text, it's common for the text to extend beyond the boundaries of the image and become invisible. I'm looking for a way to color the overflowing text in the same shade as the background image (blue). ...

Implement a new method called "defer" to an array that will be resolved at a later time using Promise.all()

I need to manage a queue of DB calls that will be executed only once the connection is established. The DB object is created and stored as a member of the module upon connection. DB Module: var db = { localDb: null, connectLocal: (dbName) => { ...

preventing users from selecting past dates on Full Calendar Plugin

Is there a way to disable the previous month button on the full calendar? Currently it is April. When I click on the previous button, the calendar shows March instead of disabling. How can this be prevented? http://jsfiddle.net/6enYL/ $(document).ready( ...

Having trouble with control flow in Node.js and Mongoose?

Recently, I've dived into exploring node.js and have some familiarity with JavaScript, although my experience in server-side programming is quite minimal. The situation at hand involves the code below where I aim to add a product to the collection us ...

Nextjs is facing challenges in enhancing LCP specifically for text content

I've been trying to boost my LCP score by optimizing the text on my page, but it seems stuck and I can't figure out why my LCP isn't improving. Take a look at the screenshot: https://i.stack.imgur.com/xfAeL.png The report indicates that &a ...

What is the best way to generate hyperlinks from data in a MongoDB database?

Looking for some assistance in setting up an online discussion forum using node.js, express & mongodb. My current challenge is creating clickable links that will redirect me to the specific page of each article stored in the database. I need to figure out ...

Submit a photo with a unique identifier to a swiftAPI endpoint using a POST request from a ReactJS application

Attempting to send an image from the client side (ReactJS) to FastAPI using a POST method This is the code on the client side: const [img, setImg] = useState(null) const onImageUpload = (e) => { console.log(e.target.files[0]) setImg(e. ...

Sorting WordPress entries by nearby locations

I have WordPress posts that are being displayed on a Google Map. The posts are pulling data from a custom post field that contains the latlng value, where latitude and longitude are combined into one. Additionally, the map shows the user's location u ...

What is the best way to include a new class into the current class in this particular scenario?

Just starting out with Javascript and Jquery, so please bear with me if this question seems basic I'm dynamically constructing HTML like this: var favoriteresultag = '<ul>'; favoriteresultag += "<section id='"+name+"' ...

Issue with onExited method in material-ui component not functioning as expected

I'm attempting to implement the onExited method (Material-UI v1.0.0-beta.41) in my React.js code like this: fireOnExit=()=>{ alert("Exited"); } <button label="Cancel" onClick={this.handleClose} onExited{()=>this.fireOnExit()}/> Unfo ...