描述
我试图在一个function应用程序中使用Material的theme.spacing函数,但是间隔函数没有被识别。
Javascript错误消息是:TypeError: theme.spacing不是函数
我不确定这是否是一个bug,或者我安装的框架版本有问题。
上下文
paddingTop: theme.spacing(20)中。根据package-lock.json文件,这些是正在安装的框架版本:
发布于 2019-02-09 19:11:37
事实上,这毕竟是由请求#14099引起的一个bug。
解决方案正在进行中,所以我要结束这个问题。
发布于 2021-11-10 14:09:26
对于实质性ui版本5.1.0,以下内容对我有效(如@Worm所说)
import { makeStyles } from '@mui/styles';记住安装@mui/styles
如果你收到这样的警告
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.用ThemeProvider包装父容器
export default ParentComponentName = (props)=>{
return(
<ThemeProvider theme={theme}>
<SomeThemeComponent>
<SomeComponent />
</SomeThemeComponent>
<ThemeProvider>
)
}参考文献
https://mui.com/styles/api/#examples-4
PS:张贴作为新的答案,因为我不能评论,因为信贷限额。
发布于 2019-09-21 06:15:08
尝尝这个。
import { makeStyles } from '@material-ui/core/styles'
const userStyles = makeStyles (theme => ({
gridAlign : {
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.secondary,
},
})https://stackoverflow.com/questions/54609338
复制相似问题