【问题标题】:Is it allowed to use MuiThemeProvider for a component?是否允许将 MuiThemeProvider 用于组件?
【发布时间】:2018-04-10 14:26:29
【问题描述】:

我有一个组件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 这样的非根组件是错误的吗?

【问题讨论】:

    标签: javascript reactjs material-ui


    【解决方案1】:

    根据documentation,可以随意嵌套MuiThemeProvider

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多