reactjs - MUI v5:失败的道具类型:`Grid`的道具`direction`只能与`container`道具一起使用
问题描述
我正在设计一个 MUI v5 Grid
,如下所示:
const SettingsGrid = styled(Grid)(({ theme }) => ({
width: `calc(100% - calc(${Number(theme.spacing(2))} * 2))`,
margin: theme.spacing(2),
'& .MuiCard-root + .MuiTypography-subtitle1': {
marginTop: theme.spacing(4),
},
}))
然后,我按如下方式使用它:
<Box m={1} overflow="auto">
<SettingsGrid
container
direction="row"
justifyContent="center"
>
<Grid
direction="column"
style={{ minWidth: '35em', maxWidth: '60em' }}
>
<!-- ... -->
</Grid>
</SettingsGrid>
</Box>
这现在会在运行时引发此控制台警告:
Failed prop type: The prop `direction` of `Grid` can only be used together with the `container` prop.
我试过了,container={true}
但这没有帮助。似乎container
财产丢失了styled()
。我怎样才能解决这个问题?我不知所措。
解决方案
你的direction
道具只有在道具设置Grid
为时才有效,所以在你的内部添加缺少的道具。在内部,如果布局不是 flex ,容器的 display 设置为,并且映射到,是没有意义的:container
true
container
Grid
Grid
flex
direction
flex-direction
flex-direction
<Grid container direction='column'
推荐阅读
- javascript - 如何合并两个数组对象
- vue.js - 将 Vuex 传递给实例化组件的最佳方式?
- css - 如何设置输入类型选择的下拉菜单?
- vb.net - Visual Basic 将字符串转换为音频 (WAV) 文件并播放
- python-3.x - Python3 如何 asyncio.gather() 部分函数列表
- meteor - Meteor 帐户密码:TypeError:Accounts.setPassword 不是函数
- ios - 为什么 Firebase 远程配置不更新值?
- apache-spark - MicroBatchExecution Spark 结构化流与 Kafka 2.4.0
- java - 为什么 Spark 数据帧缓存在这里不起作用
- java - 如何在 RTP 序列中包含所有 AudioFormat?