【发布时间】:2021-12-01 05:20:59
【问题描述】:
我正在设计 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() 中丢失了。我怎样才能解决这个问题?我很茫然。
【问题讨论】:
-
请提供code sandbox 重现问题。
-
@TheDiveO 尝试在内部
Grid中设置container,我认为您在那里缺少container道具。在 Codesandbox 上确认它可以使用或不使用styled。 -
Arg,谢谢。它是内部网格,而不是外部网格。
标签: reactjs material-ui styled-components