允许使用MuiThemeProvider作为组件吗?

时间:2018-04-10 14:26:29

标签: javascript reactjs material-ui

我有一个组件View

import React from 'react';
import { AppBar, Toolbar } from 'material-ui';
import { Typography } from 'material-ui';
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import {lightBlue} from 'material-ui/colors';

const theme = createMuiTheme({
  palette: {
    primary: {main:lightBlue['A700']}
  },
});

const View = (props) => (
  <MuiThemeProvider theme={theme}>
    <AppBar position="static">
      <Toolbar>
      <Typography variant="title">
        {props.title}
      </Typography>          
      </Toolbar>
    </AppBar>
  </MuiThemeProvider>
);
export default View;

如您所见,该组件使用自己的MuiThemeProvider。 View组件不是整个应用程序的根组件,它是App根组件的子组件,App组件包含多个组件。

我的问题是,将MuiThemeProvider分配给非View之类的根组件是错误的吗?

1 个答案:

答案 0 :(得分:1)

根据documentation,您可以根据需要嵌套MuiThemeProvider