gpt4 book ai didi

reactjs - Material 界面 : Cannot read property 'button' of undefined

转载 作者:行者123 更新时间:2023-12-04 14:14:38 26 4
gpt4 key购买 nike

import { createMuiTheme, ThemeOptions } from '@material-ui/core/styles';

const theme = (options: ThemeOptions) => {
return createMuiTheme({
palette: {
primary: {
main: '#b5ddd1'
},
secondary: {
main: '#b2d9ea'
},
},
typography: {
fontFamily: 'Raleway, Arial',
button: {
fontStyle: 'italic',
},
},
...options,
})
}

提供者
import { ThemeProvider } from '@material-ui/core/styles'

<Provider store={store}>
<ConnectedRouter>
<ThemeProvider theme={theme}>
<GlobalStyles/>
{/*<ErrorBoundary>*/}
{/*<Layout>*/}
<Component {...pageProps} />
{/*</Layout>*/}
{/*</ErrorBoundary>*/}
</ThemeProvider>
</ConnectedRouter>
</Provider>
import Button from '@material-ui/core/Button'

<div>
<div>Log into APP</div>
<Button>Test</Button>
</div>

但我仍然在 Button.js 中遇到错误

在样式 (/Users/filipbrezina/Documents/Projekty/sportee-frontend/node_modules/
material-ui/core/Button/Button.js:33:78

有人能帮助我吗?我不知道我做错了什么😏

最佳答案

您定义/提供 theme 的方式有误:

你需要像这样提供它:

<ThemeProvider theme={theme({})}> {/* function call: theme({}) */}

或者,如果你这样定义它:
const theme = createMuiTheme({
palette: {
primary: {
main: '#b5ddd1',
},
// you can add more options
}
})

你可以这样提供:
<ThemeProvider theme={theme}>

关于reactjs - Material 界面 : Cannot read property 'button' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61650475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com