After I created ThemeSetting.tsx context I cannot use
<Button><Button>
and all things that use theme
of materialUI
ReactJS , Typescript
error
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({
and 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>;
};
Just ran into this myself. You can import createTheme
from @mui/material/styles
or @mui/system
, but they do slightly different things:
You can use the utility coming from the
@mui/system
package, or if you are using@mui/material
, you can import it from@mui/material/styles
. The difference is in the defaulttheme
that is used (if no theme is available in the React context).
The one from @mui/material/styles
is smart enough to fill in gaps in the active theme from the default MUI theme. So if you're using @mui/material
, then use @mui/material/styles
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With