styled-components: Styled-components doesn't work with Material UI
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 18 (6 by maintainers)
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:
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.
@aeciolevy https://codesandbox.io/s/54q2j9881l
@unutoiul that is something we don’t do, since in styled-components that’d be an anti-pattern. So if you don’t want to migrate straight away, you’d have to keep your CSS Modules (or sth equivalent of course) tooling around.
In styled-components all styling is combined in JS, so this is definitely not a question, of how to make it work with styled-components exclusively.
styled-components interoperability with Material-UI is documented under this page: https://material-ui-next.com/guides/interoperability/#styled-components.