覆盖MaterialUI MuiCheckbox图标默认道具

时间:2020-09-02 00:16:03

标签: reactjs material-ui material-design

我想在整个项目中使用自定义SVG图标覆盖MuiCheckbox图标,例如iconindeterminateIcon道具。

我正在使用自定义主题:

import { CustomBlankIcon, CustomIndeterminateIcon } from "./Icons";

const theme = responsiveFontSizes(
  createMuiTheme({
    props: {
      MuiCheckbox: {
          icon: CustomBlankIcon,
          indeterminateIcon: CustomIndeterminateIcon
      }
    },
  })
);

但是,这不起作用,它抛出了一个错误:

Cannot read property 'fontSize' of undefined

关于如何覆盖此主题配置文件中的默认图标道具的任何想法吗?

1 个答案:

答案 0 :(得分:2)

您应该传递node而不是函数/组件名称,请尝试

import { CustomBlankIcon, CustomIndeterminateIcon } from "./Icons";

const theme = responsiveFontSizes(
  createMuiTheme({
    props: {
      MuiCheckbox: {
          icon: <CustomBlankIcon />,
          indeterminateIcon: <CustomIndeterminateIcon />
      }
    },
  })
);