我试图改变mui主题的原色,但是当我应用它的时候,我得到了各种各样的错误。
import { createTheme, ThemeProvider } from "@mui/system";
import "./App.css";
import IntegrationsPage from "./pages/integrations/IntegrationsPage";
function App() {
const theme = createTheme({
palette: {
primary: {
main: "#4B68FE",
}
}
});
return (
<div className="App">
<ThemeProvider theme={theme}>
<IntegrationsPage/>
</ThemeProvider>
</div>
);
}
export default App;
以下是错误。不设置主题时,错误不会出现。
Uncaught TypeError: Cannot read properties of undefined (reading '1')
at Paper (Paper.js:81:1)
at renderWithHooks (react-dom.development.js:16305:1)
at updateForwardRef (react-dom.development.js:19226:1)
at beginWork (react-dom.development.js:21636:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
at invokeGuardedCallback (react-dom.development.js:4277:1)
at beginWork$1 (react-dom.development.js:27451:1)
at performUnitOfWork (react-dom.development.js:26557:1)
at workLoopSync (react-dom.development.js:26466:1)
Paper @ Paper.js:81
我需要设置所有的主题值吗?如果我只想改变主颜色呢?
1条答案
按热度按时间g6ll5ycj1#
这里你正在传递你的新的
theme
到provider
你没有更新主题.如果你想改变原色,你应该在你导入主题的文件中改变它.
如果你没有任何主题,你的代码是好的,你只需要从
@mui/material/styles
导入createTheme
和ThemeProvider