question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Styled-components doesn't work with Material UI

See original GitHub issue

Styled-components doesn’t work with Material UI

I’m trying to style material-ui component using styled components and doesn’t work

Example of code:

import Button from 'material-ui/Button';
const StyledButton = styled(Button)`
    background: red;
    border: 1px solid red;
    font-size: 2rem;
    font-weight: bold;
`;

class ButtonTemplate extends Component {
    render() {
        return(
            <div>
                <StyledButton />
            </div>
        )
    }
}

I get only the normal styling of material UI button…what’s is the issue?

Thanks, Lucas

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

71reactions
kittencommented, Nov 1, 2017

There’s a guide here: https://www.styled-components.com/docs/advanced#existing-css

Also, you can try to increase the specificity of your SC CSS:

import Button from 'material-ui/Button';

const StyledButton = styled(Button)`
    && {
    background: red;
    border: 1px solid red;
    font-size: 2rem;
    font-weight: bold;
    }
`;
7reactions
Danilo-Araujo-Silvacommented, Jan 10, 2018

Looks like we have 3 ways (could be easier, but not everything is flowers) to override Material UI styles with Styled Components. Here is my Gist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

styled-components doesn't work with material-ui
hi friends, i am using material-ui with reactjs to create a website, then i want to add my custom style with help styled-component...
Read more >
New Material-UI v5 not working with styled-components and ...
62 votes, 28 comments. I'm trying to use the new Material-UI v5 that just came out but am having trouble using it with...
Read more >
Style library interoperability - Material UI - MUI
If you are already using a custom theme with styled-components or Emotion, it might not be compatible with MUI's theme specification. If it's...
Read more >
How to Styled Component in Material UI #31 - YouTube
Material UI Playlist: https://www.youtube.com/playlist?list=PLlR2O33QQkfXnZMMZC0y22gLayBbB1UQdHey Everyone,In this video you will be able to ...
Read more >
Styled Components in Material UI (MUI) with Styled Utility
Always make sure that the first letter of the variable is capital because it will work like a component and a component name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found