Ija*_*yam 7 javascript reactjs material-ui
之前使用 v4 的代码是
const useStyles = makeStyles(theme => ({
toolbarMargin: {
...theme.mixins.toolbar
}
}))
Run Code Online (Sandbox Code Playgroud)
如何使用sxprop 将此代码迁移到 MUI v5,我尝试像这样使用它
<Box
sx={{
...(theme) => theme.mixins.toolbar,
}}
/>
Run Code Online (Sandbox Code Playgroud)
但theme没有定义。
您可以执行以下操作:
<Box sx={theme => theme.mixins.toolbar} />
Run Code Online (Sandbox Code Playgroud)
或者
<Box sx={theme => ({
...theme.mixins.toolbar,
// other sx stuff
})} />
Run Code Online (Sandbox Code Playgroud)
theme由于您还可以将带有参数的函数传递给sxprop,因此它必须返回有效的 sx 对象。
| 归档时间: |
|
| 查看次数: |
2688 次 |
| 最近记录: |