【发布时间】:2019-09-02 04:04:13
【问题描述】:
我在声明我的 MuiProvider 时有一段代码,如下所示:
<MuiThemeProvider theme={merge(defaultGlobalTheme, this.props.adjustThemeOptions)}>
{this.props.children}
</MuiThemeProvider>
如何使用 Material-UI Hooks(在 @material-ui/styles@3.0.0-alpha.10 中声明)使用我的自定义主题(在 MuiThemeProvider 中使用 @material-ui/core@3.9.3 库声明)还是使用 Hooks 的其他解决方案?
编辑: 你可以这样消费:
import { useTheme } from '@material-ui/styles';
function MyComponent() {
const theme = useTheme();
return <div>{`spacing ${theme.spacing}`}</div>;
}
但是我的解决方案有效如果您在上述版本中有带有@material-ui/core 的组件并且您正在使用@material-ui/styles 库。
提前谢谢你。
最好, 弗兰
【问题讨论】:
标签: reactjs material-ui react-hooks