Creating dynamic styles in ReactJS using the makeStyles feature

My theme is unique and I excel in theming. Currently, I have developed three distinct styles using material UI tabs. To modify these styles, I am utilizing makeStyles.

Below is an example of the tab that requires modification:

...

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
    width: "100%",
    backgroundColor: theme.pallete.primary
  },
  tabs: {
  /// some styles
  }
...
}
));

...


<Tabs
 ...someProps
 className={classes.tabs}
>

The elements inside the tab have specific classes:

 <button class="MuiButtonBase-root MuiTab-root MuiTab-textColorSecondary Mui-selected MuiTab-labelIcon">

I attempted to edit the styles similarly to:

... = createMuiTHeme ({
overrides: {
...some overrides
}

In my case:

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
    width: "100%",
    backgroundColor: "#121D42",
   MuiButtonBase: {
    root: {
    ///some styles
    },
   }
  },
...

However, this approach does not work with makeStyles(). Therefore, I am seeking a solution to edit buttons inside tabs using makeStyles(), or any other helpful suggestions are appreciated.

Answer №1

I have come across a temporary fix that seems to work for now.

By using Styled Components and creating a styled element, we can easily change styles. One key component to utilize is StylesProvider.

const NewButton = styled(({styledComponentProp, ...rest}) => (
  <Button classes={{label: 'label'}} {...rest}/>
))`
  .label {
    color: blue;
    font-size: ${props => props.styledComponentProp};
}  
`

export const BlueButton = styled(props => {
  return (

    <StylesProvider injectFirst>
    <NewButton variant="contained" styledComponentProp="20px"> Red Labeled Button </NewButton>
  </StylesProvider>
  );
})`

`;

Is there a more efficient solution available?

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

Error message "node:internal/modules/cjs/loader:1056 throw err;" was encountered

I am currently working with Node.js version 19.4.0. Whenever I attempt to create a React project in Visual Studio Code using the command npx create-react-app MyApp, I encounter the following error: node:internal/modules/cjs/loader:1056 throw err; ^ E ...

Bottom div refuses to adhere to the bottom of the page

I need help with creating a footer div that sticks to the bottom, left, and right of the page. The current footer doesn't extend all the way down and left. How can I resolve this without using "position: fixed;"? Below is the code snippet (I have rep ...

What is the best way to evenly space out divs filled with images in a horizontal layout?

On my website, the header consists of text and a logo. Since the font used is not standard, the text is displayed as an image. I am looking to create a design in which the elements of the site adjust according to the size of the browser window. Is this wh ...

Is it possible to access the reference of a component in a different component?

Within my component called Box, I am returning a mesh object that belongs to the Object3d type. The challenge I face now is how to obtain a reference to this particular object in my Floor component. I attempted assigning another ref in my App component and ...

I am looking to eliminate any unnecessary gaps within the list group

I'm currently learning how to create a sidebar in my project. Whenever item 3 is expanded, an unwanted rectangular area appears underneath it. I have not added any padding in my code nor any CSS styles. I attempted to use browser inspect tools, but ...

Developing User Registration functionality in Keycloak for both Flutter and React User Interfaces

I am currently working on a project that involves a blend of Flutter frontend, React frontend, and a Spring Boot backend. My goal is to manage authentication using Keycloak, but I have hit a roadblock. It seems that I am unable to locate a REST endpoint in ...

Issue with background color not being displayed in print preview on Internet Explorer

How can I ensure that IE will display the circles when printing? I am currently using this code: <li ng-repeat="items in ferdigheter">{{ items.title}} <div class="circles"> <div class="circle" ng-repeat="a in thisnumber(items.stars)"&g ...

Formatting an invoice document with Bootstrap 4

Currently in my VueJS project, I am constructing an invoice form with the help of Bootstrap 4. Utilizing this snippet, everything has been running smoothly so far. However, I seem to be struggling when it comes to styling the UI at the moment. The issue I ...

Ways to adjust the CSS height of a fluid body and flexible footer

In a nutshell, I'm dealing with 3 elements: <div> <Header/> </div> <div> <Body/> </div> <div> <Footer/> </div> The header has a fixed height. ...

Are DIV elements really impossible to click using selenium Web Driver?

Can DIV elements be clicked using selenium Web Driver? For example, I'm having trouble clicking the delete button in Gmail. https://i.stack.imgur.com/zsyio.png I've been trying to locate the element using the XPATH = //div[@aria-label='De ...

What is the best way to modify a Stripe paymentIntent in a Node.js environment?

I'm currently in the process of developing a donation form for a non-profit organization, and I'm facing challenges when it comes to updating the payment amount that is sent to my Node.js Stripe backend. On the frontend, I am using React and uti ...

How to Align Navigation Bar in the Center and Place it on Top of the Bottom Section of the Banner Image

Hello! I am relatively new to the world of HTML and CSS, so any help you can provide is greatly appreciated. Currently, I am trying to center a navigation bar while also having it overlap on the bottom side of a banner image. The top of the page features ...

Switching up the Button onClick variant in Material-UI (MUI)

I'm looking to dynamically change the variant of a Button component from 'outlined' to 'contained' whenever it is clicked: <Button variant='outlined'>Click me to change my variant to contained</Button> Is thi ...

Setting the state based on Promise values within a loop

I am currently facing a challenge in my React project where I am using axios to interact with an external API. The goal is to loop through the array of objects retrieved from the API call and utilize the values returned by a separate function within the ...

The error message "TypeError: Cannot access 'url' property of undefined in Strapi

I am facing an issue with a list of items where some have download links while others do not. Whenever I try to render an undefined URL, it triggers an error. To resolve this, I attempted the following: if (spectacle.pdf.url) { const pdf = spectacle.p ...

Using a local image as a background with the fill option: a simple guide

background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffffff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.6 ...

Dynamically updating the column header title in a React Table

I am currently utilizing React Table within my dashboard project. My goal is to dynamically change the column header name of the React Table based on each click of a tab. I have been passing the state named "tabName" as props in React Table, but unfortunat ...

The attribute 'Error' is not available for the object of type 'MovieData | ResponseError'. This attribute is also not present in objects of type 'MovieData'

Question Answered I am currently working with two interfaces, MovieData and ResponseError. export interface MovieData { Poster: string; Title: string; Plot: string; imdbID: string; } The ResponseError interface looks like this: export interface R ...

Material-UI-Next powered Dropbox Component in React

Is it possible to nest a dropdown component with MenuItem in React? I want to create a single component for drop downs instead of nesting multiple components. Am I heading in the right direction or should drop down components be treated differently? App. ...

Introducing a new feature called Space Break which allows for

Can CSS be used to convert spaces into line breaks? For example, given this HTML: <li>This and That</li> I want it to display like: This and That ...