我正在做一个使用MUI和Sass的Reaction项目.目前有多个满!important
的SCSS文件用sass覆盖MUI样式.为了解决这个问题,我go 掉了!important
,并添加了:
import { StyledEngineProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline'
<CssBaseline />
<StyledEngineProvider injectFirst>
*** component tree here ***
</StyledEngineProvider>
它一开始似乎起作用,但当你专注于一个组件时就停止工作了.例如,将鼠标悬停在以下位置时,此按钮将变为白色并带有蓝色边框:
SCSS
.button {
width: 250px;
height: 50px;
border: 1px solid grey;
border-radius: 15px;
text-transform: none;
}
.go-button {
@extend .button;
background-color: grey;
color: whitesmoke;
}
反作用力
<Button
className="go-button"
variant="outlined"
onClick={handleClick}
>
Go
</Button>
我们没有使用模块或Make Styles.在没有!important
的情况下,改写MUI的最佳方式是什么?