d3tr1tus
d3tr1tus

Reputation: 799

Material UI: Cannot read property 'button' of undefined

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,
    })
}

provider

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>

But I am still getting error in Button.js

at styles (/Users/filipbrezina/Documents/Projekty/sportee-frontend/node_modules/ material-ui/core/Button/Button.js:33:78

Can someone help me please? I don't know what am I doing wrong 😏

Upvotes: 4

Views: 2807

Answers (1)

Ajeet Shah
Ajeet Shah

Reputation: 19863

There is an error in the way you are defining / providing the theme:

You need to provide it like this:

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

Or if you define it like this:

const theme = createMuiTheme({
  palette: {
    primary: {
      main: '#b5ddd1',
    },
    // you can add more options
  }
})

you can provide it this way:

<ThemeProvider theme={theme}>

Upvotes: 4

Related Questions