我正在使用Material-UI的paperbase高级主题:
https://material-ui.com/premium-themes/paperbase/
并查看源代码,我尝试执行以下操作:
// App.tsx
import * as React from 'react';
import './App.css';
import Paperbase from './components/Paperbase'
class App extends React.Component {
public render() {
return (
<div className="App">
<Paperbase />
</div>
);
}
}
export default App;
// Paperbase.js
import React from 'react';
import PropTypes from 'prop-types';
import { createMuiTheme, withStyles } from '@material-ui/core/styles';
import { ThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import Hidden from '@material-ui/core/Hidden';
import Navigator from './Navigator';
import Content from './Content';
import Header from './Header';
let theme = createMuiTheme({
typography: {
h5: {
fontWeight: 500,
fontSize: 26,
letterSpacing: 0.5,
},
},
palette: {
primary: {
light: '#63ccff',
main: '#009be5',
dark: '#006db3',
},
},
shape: {
borderRadius: 8,
},
});
theme = {
...theme,
overrides: {
MuiDrawer: {
paper: {
backgroundColor: '#18202c',
},
},
MuiButton: {
label: {
textTransform: 'initial',
},
contained: {
boxShadow: 'none',
'&:active': {
boxShadow: 'none',
},
},
},
MuiTabs: {
root: {
// marginLeft: theme.spacing(1),
},
indicator: {
height: 3,
borderTopLeftRadius: 3,
borderTopRightRadius: 3,
backgroundColor: theme.palette.common.white,
},
},
MuiTab: {
root: {
textTransform: 'initial',
margin: '0 16px',
minWidth: 0,
padding: 0,
[theme.breakpoints.up('md')]: {
padding: 0,
minWidth: 0,
},
},
},
MuiIconButton: {
root: {
// padding: theme.spacing(1),
},
},
MuiTooltip: {
tooltip: {
borderRadius: 4,
},
},
MuiDivider: {
root: {
backgroundColor: '#404854',
},
},
MuiListItemText: {
primary: {
fontWeight: theme.typography.fontWeightMedium,
},
},
MuiListItemIcon: {
root: {
color: 'inherit',
marginRight: 0,
'& svg': {
fontSize: 20,
},
},
},
MuiAvatar: {
root: {
width: 32,
height: 32,
},
},
},
props: {
MuiTab: {
disableRipple: true,
},
},
mixins: {
...theme.mixins,
toolbar: {
minHeight: 48,
},
},
};
const drawerWidth = 256;
const styles = {
root: {
display: 'flex',
minHeight: '100vh',
}
};
class Paperbase extends React.Component {
state = {
mobileOpen: false,
};
handleDrawerToggle = () => {
this.setState(state => ({ mobileOpen: !state.mobileOpen }));
};
render() {
const { classes } = this.props;
return (
<ThemeProvider theme={theme}>
<div className={classes.root}>
<CssBaseline />
<nav className={classes.drawer}>
<Hidden smUp implementation="js">
<Navigator
PaperProps={{ style: { width: drawerWidth } }}
variant="temporary"
open={this.state.mobileOpen}
onClose={this.handleDrawerToggle}
/>
</Hidden>
<Hidden xsDown implementation="css">
<Navigator PaperProps={{ style: { width: drawerWidth } }} />
</Hidden>
</nav>
<div className={classes.appContent}>
<Header onDrawerToggle={this.handleDrawerToggle} />
<main className={classes.mainContent}>
<Content />
</main>
</div>
</div>
</ThemeProvider>
);
}
}
Paperbase.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(Paperbase);
我收到一个错误消息:
Check the render method of `Paperbase`.
我对React非常陌生,并尝试在我的示例应用程序中使用此重要的ui主题。但是,不确定这里发生了什么以及为什么它抱怨render方法。我尝试在互联网上寻找可能的解决方案,但找不到适用于此情况的任何内容。有人可以帮助解决此问题吗?我肯定在做一些愚蠢的事情。
答案 0 :(得分:1)
将ThemeProvider
替换为MuiThemeProvider
,要使用ThemeProvider
,您应该使用:
import { ThemeProvider } from '@material-ui/styles';