【发布时间】:2021-11-30 04:49:33
【问题描述】:
我是第一次使用 Material-UI v5,我想用createTheme 创建一个自定义主题来设置按钮组件的样式。根据documentation:
主题的
components键允许您自定义组件而无需将其包装在另一个组件中。您可以更改样式、默认道具等。
他们提供了一个代码示例:
const theme = createTheme({
components: {
// Name of the component
MuiButtonBase: {
defaultProps: {
// The props to change the default for.
disableRipple: true, // No more ripple!
},
},
},
});
但是当我尝试实现它时,似乎没有createTheme 的组件键。我收到以下错误:
Argument of type '{ components: any; }' is not assignable to parameter of type 'ThemeOptions'.
Object literal may only specify known properties, and 'components' does not exist in type 'ThemeOptions'
这里可能有什么问题?
【问题讨论】:
-
您使用的是 MUI v4 还是 v5?
-
如果你使用 typescript,你可能需要定义你的主题的属性类型:mui.com/customization/theming
-
我正在使用 v5 @NearHuscarl
-
您的代码在 v5 上运行良好,您可以准备一个代码框吗?
-
我正在使用打字稿,但我认为只有在创建自定义变量时才需要@BrunoFarias
标签: reactjs material-ui