theme.spacing is not a function with @material-ui/[styles/core] 4.0.1

See original GitHub issue

Trying to fix another issue today I tried to reset my whole Material-UI 4.0.0 workspace, migrating both core and style to latest 4.0.1

As soon as I try to use a ThemeProvider I get TypeError theme.spacing is not a function.

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate. Well… not exactly… I found a duplicate at https://github.com/mui-org/material-ui/issues/15834 but the fix seems not working, it’s like the bad usage is in the core

Expected Behavior 🤔

Just want to see the theming working. I’m confused by the fact that theme.spacing seems used by both master and next branches, so this seems the way to go.

Current Behavior 😯

See error above

Steps to Reproduce 🕹

Link: https://codesandbox.io/s/materialui-style-issue-rk8n0

Context 🔦

I started a whole new application and I’m trying to clue together all of the style feature of Material-UI. That said, before the migration to 4.0.1 of style module I had not such issues, so I’m unsure if 4.x releases are someway unstable or what.

Your Environment 🌎

Tech Version
Material-UI v4.0.1
React 16.0.6
Browser FF/Chrome latest
TypeScript -

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

110reactions
ByronHsucommented, Jun 7, 2019

Sorry I found the problem. I change import { withStyles } from '@material-ui/styles'; to import { withStyles } from '@material-ui/core/styles'; and everything works fine. Thanks!

36reactions
x5enginecommented, Sep 2, 2019

go from marginRight: theme.spacing(1)

change it to marginRight: theme.spacing.unit

Read more comments on GitHub >

github_iconTop Results From Across the Web

theme.spacing is not a function with @material-ui/[styles/core ...
Trying to fix another issue today I tried to reset my whole Material-UI 4.0.0 workspace, migrating both core and style to latest 4.0.1....
Read more >
Why Material-UI is not recognizing the theme.spacing function?
I am trying to use Material-UI's theme.spacing function in a React application but the spacing function is not recognized.
Read more >
Spacing - Material UI - MUI
Use the theme.spacing() helper to create consistent spacing between the elements of your UI. MUI uses a recommended 8px scaling factor by default....
Read more >
[Solved]-TypeError: theme.spacing is not a function-Reactjs
This is not working because you have to type your Theme. import the Theme import { Theme } from '@mui/material'. Now type it:...
Read more >
Spacing Guidelines · Magma Documentation - GitHub Pages
spacing() helper which too uses an 8px scaling factor. const theme = createTheme(); theme.spacing(0.5) // = 8 * 0.5 (4px) theme.spacing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found