theme.spacing is not a function with @material-ui/[styles/core] 4.0.1
See original GitHub issueTrying 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:
- Created 4 years ago
- Comments:22 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry I found the problem. I change
import { withStyles } from '@material-ui/styles';toimport { withStyles } from '@material-ui/core/styles';and everything works fine. Thanks!go from
marginRight: theme.spacing(1)change it to
marginRight: theme.spacing.unit