I'm trying to include some ponents from @material-ui package at my app, using the ThemeProvider at the root, but i'm having some troubles.
Other ponents that use styles defined locally (without theme properties) render ok.
sandbox:
Here is how the theme is being created:
import React from "react";
import { createMuiTheme } from "@material-ui/core/styles";
import { ThemeProvider } from "@material-ui/styles";
import { blue, white } from "@material-ui/core/colors";
function AppTheme(props) {
const theme = createMuiTheme({
palette: {
primary: blue,
text: white
}
});
return <ThemeProvider theme={theme}>{props.children}</ThemeProvider>;
}
export default AppTheme;
I'm trying to include some ponents from @material-ui package at my app, using the ThemeProvider at the root, but i'm having some troubles.
Other ponents that use styles defined locally (without theme properties) render ok.
sandbox: https://codesandbox.io/s/theme-provider-issues-t72f3
Here is how the theme is being created:
import React from "react";
import { createMuiTheme } from "@material-ui/core/styles";
import { ThemeProvider } from "@material-ui/styles";
import { blue, white } from "@material-ui/core/colors";
function AppTheme(props) {
const theme = createMuiTheme({
palette: {
primary: blue,
text: white
}
});
return <ThemeProvider theme={theme}>{props.children}</ThemeProvider>;
}
export default AppTheme;
Share
Improve this question
edited Jun 18, 2019 at 21:52
Ryan Cogswell
81.3k9 gold badges241 silver badges212 bronze badges
asked Jun 18, 2019 at 21:28
dkotsukadkotsuka
631 gold badge2 silver badges7 bronze badges
2 Answers
Reset to default 4I'm not certain what you were trying to achieve with text: white
, but that created an invalid structure for your theme. theme.palette.text
should be an object rather than a color, and the error was caused by Material-UI looking for theme.palette.text.primary
.
Changing AppTheme.js to the following solves the problem:
import React from "react";
import { createMuiTheme } from "@material-ui/core/styles";
import { ThemeProvider } from "@material-ui/styles";
import { blue } from "@material-ui/core/colors";
const theme = createMuiTheme({
palette: {
primary: blue
}
});
function AppTheme(props) {
return <ThemeProvider theme={theme}>{props.children}</ThemeProvider>;
}
export default AppTheme;
I've got another error, was fixed here
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744215656a4563543.html
评论列表(0条)