我有一个使用 Create React App 创建的 React 应用程序,并使用 @material-ui/core npm 包进行主题化。
为了自定义组件,我使用 MaterialUI 提供的 withStyles 高阶组件。
根据文档,它支持嵌套 ThemeProviders https://material-ui.com/customization/theming/#nesting-the-theme。
但在子 ThemeProvider withStyles 内部不会应用类。
这是一个演示该问题的基本应用程序 - > https://codesandbox.io/s/vibrant-tree-eh83d
示例组件.tsx
import React, { FunctionComponent } from "react";
import {
WithStyles,
withStyles,
createStyles,
StepButton,
Step,
Stepper,
Box
} from "@material-ui/core";
const styles = createStyles({
button: {
"& .MuiStepIcon-root.MuiStepIcon-active": {
fill: "red"
}
}
});
interface Props extends WithStyles<typeof styles> {
title: string;
}
const ExampleComponent: FunctionComponent<Props> = ({ title, classes }) => { …Run Code Online (Sandbox Code Playgroud)