【发布时间】:2021-11-19 00:42:42
【问题描述】:
创建 ThemeSetting.tsx 上下文后,我无法使用
<Button><Button>
以及所有使用 theme 的 materialUI 的东西
ReactJS , 打字稿
TypeError: Cannot read properties of undefined (reading 'create') push../node_modules/@mui/material/Button/Button.js.Object.ownerState.ownerState node_modules/@mui/material/Button/Button.js:67
64 | minWidth: 64,
65 | padding: '6px 16px',
66 | borderRadius: theme.shape.borderRadius,
> 67 | transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color', 'color'], {
| ^ 68 | duration: theme.transitions.duration.short
69 | }),
70 | '&:hover': _extends({
和 ThemeSetting.tsx
import { createTheme, ThemeProvider } from "@mui/system";
export const ThemeContextProvider: React.FC<{}> = ({ children }) => {
const theme = createTheme({
palette: {
navbar: blue[100],
tag: {
red: red[200],
pink: pink[200],
purple: purple[200],
blue: blue[200],
green: green[200],
},
},
typography: {
fontFamily: [
"NotoSans",
"NotoSansThai",
"Arial",
"Roboto",
"'Helvetica Neue'",
"sans-serif",
].join(","),
},
shape: {
borderRadius: 15,
},
});
return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
};
【问题讨论】:
-
您应该从
@mui/material/styles导入createTheme和ThemeProvider。@mui/system中的版本是一个较低级别的部分,它不会针对@mui/material中的默认 Material Design 主题做任何特定的事情。
标签: reactjs typescript material-ui material-design