简体   繁体   English

无法通过 material-ui 中的 muiThemeProvider 标签使用主题颜色

[英]cannot use theme color by muiThemeProvider tag in material-ui

I'm working on a React-redux app project and I'm new to material-ui theming.我正在开发一个 React-redux 应用程序项目,我是 material-ui 主题的新手。 I created a theme object in a separate theme.js file, outlined as follows:我在单独的 theme.js 文件中创建了一个主题 object,概述如下:

const theme = createMuiTheme({
    palette: {
        primary: blue,
        error: {
            main: red[300],
        },
        background: {
            default: indigo[50],
        },
    }
})
export default theme;

And I rendered MuiThemeProvider in my outer layer of the app in index.js:我在 index.js 的应用程序外层渲染了MuiThemeProvider

ReactDOM.render(
    <Provider store={store}>
        <MuiThemeProvider theme={theme}>
            <App />
        </MuiThemeProvider>
    </Provider>,
    document.getElementById("root")
);

My question is that, my app's currently showing the correct background color but I don't know how to properly use the color I created in my palette in other parts of my app.我的问题是,我的应用程序当前显示正确的背景颜色,但我不知道如何在应用程序的其他部分正确使用我在调色板中创建的颜色。 For example, I tried to assign the primary color blue to a title in App.js:例如,我尝试将原色蓝色分配给 App.js 中的标题:

 <CardContent color="primary">
       TITLE
 </CardContent>

But it didn't work.但它没有用。 Everything's imported properly.一切都正确导入。 No error.没有错误。 The font color isn't changed.字体颜色没有改变。 Any idea?任何想法?

By the way, I've seen tutorial using ThemeProvider tag, what's the difference between ThemeProvider and MuiThemeProvider , which one do you recommend using in general?顺便说一句,我看过使用ThemeProvider标签的教程, ThemeProviderMuiThemeProvider有什么区别,你一般推荐使用哪一个?

Your problem is not in the theming probably, From Material-ui documentation Card Content doesn't accept the color parameter您的问题可能不在主题中,来自 Material-ui 文档卡片内容不接受颜色参数

Card Content卡片内容

I would try:我会尝试:

<CardContent>
    <Typography color="primary">
        Hello world
    </Typography>
</CardContent>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM