我正在尝试自定义我的应用程序的主题(使用Material UI):
https://material-ui.com/customization/themes/#muithemeprovider
的src / index.js:
import App from './App';
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
import { createMuiTheme } from '@material-ui/core/styles';
import red from '@material-ui/core/colors/red';
import purple from '@material-ui/core/colors/purple';
import green from '@material-ui/core/colors/green';
const theme = createMuiTheme({
palette: {
primary: green,
secondary: green,
},
status: {
danger: 'orange',
},
});
ReactDOM.render(
<MuiThemeProvider muiTheme={theme}>
<App />
</MuiThemeProvider>
, document.getElementById('root'));
的src / App.js:
import { withTheme } from '@material-ui/core/styles'
class App extends Component {
...
}
export default withTheme()(App);
答案 0 :(得分:5)
这一行:
<MuiThemeProvider muiTheme={theme}>
需要:
<MuiThemeProvider theme={theme}>
答案 1 :(得分:0)
我认为你错过了withTheme()
https://material-ui.com/customization/themes/#withtheme-component-component
在Root
组件中,您应该导出:
import { withTheme } from '@material-ui/core/styles';
export default withTheme()(Root);