SSR Next.js,材料用户界面:无法读取未定义的属性“按钮”

时间:2020-05-05 05:15:13

标签: reactjs material-ui next.js styled-components

js和我想在SSR中使用Material UI。我进行了here这样的设置,但出现了错误Cannot read property 'button' of undefined

theme.ts

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

const theme = (options: ThemeOptions) => {
    return createMuiTheme({
        palette: {
            primary: {
                main: '#b5ddd1'
            },
            secondary: {
                main: '#b2d9ea'
            },
        },
        ...options,
    })
}

Next.js说我在_document.tsx中有问题

import { ServerStyleSheets, ThemeProvider } from '@material-ui/core/styles'
import theme from '../src/common/theme'

...

ctx.renderPage = () =>
                originalRenderPage({
                    enhanceApp: (App: any) => (props: any) => sheet.collectStyles(sheets.collect(<ThemeProvider theme={theme}><App {...props} /></ThemeProvider>)),
                })

我不确定我在做错什么吗?

感谢您的帮助! ??

0 个答案:

没有答案