Why Material-UI is not recognizing the theme.spacing function?

For material ui version 5.1.0 the following worked for me (as @Worm said)

  • importing makestyles like this
import { makeStyles } from '@mui/styles';

remember to install @mui/styles

if you get a warning like

MUI: The `styles` argument provided is invalid.
You are providing a function without a theme in the context.
One of the parent elements needs to use a ThemeProvider.
MUI: The `styles` argument provided is invalid.
You are providing a function without a theme in the context.
One of the parent elements needs to use a ThemeProvider.

wrap parent container with ThemeProvider

export default ParentComponentName = (props)=>{
return(
   <ThemeProvider theme={theme}>
      <SomeThemeComponent>
        <SomeComponent />
      </SomeThemeComponent>
    <ThemeProvider>
)
}

Reference

https://mui.com/styles/api/#examples-4

PS: posted as new answer as I couldn't comment,because of credit limits.


Well, it turns out this is a bug after all, caused by request #14099.

A fix is on the way now, so I am closing this question.