[英]Warning: Failed prop type: Invalid prop `xs` supplied to `ForwardRef(Grid)` - Error in Material UI Grid
<React.Fragment>
<CssBaseline />
<ThemeProvider theme={theme}>
<Grid container direction='column'>
<Grid item container>
<Header/>
</Grid>
<Grid item container>
<Grid item xs={0} sm={2}/>
<Grid item container xs={12} sm={8}>
<Switch>
<Route path="/bouquets">
<Bouquets />
</Route>
<Route path='/about'>
<About />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Grid>
<Grid item xs={0} sm={2}/>
</Grid>
</Grid>
</ThemeProvider>
</React.Fragment>
I get the error in the title in the console when running my react app.运行我的反应应用程序时,我在控制台的标题中收到错误。 This is Material UI Grid component, and I don't really understand the error or how to fix it.
这是 Material UI Grid 组件,我不太了解错误或如何修复它。
You are mixing properties in the GRID component.您正在混合 GRID 组件中的属性。
Following the mui documentation:https://mui.com/components/grid/#grid-with-multiple-breakpoints按照 mui 文档:https://mui.com/components/grid/#grid-with-multiple-breakpoints
<Grid container spacing={2}>
<Grid item xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid item xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid item xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid item xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid>
As you can see you have first the Grid with property container.如您所见,您首先拥有带有属性容器的 Grid。 Then inside you can use as many Grid with property item as you want.
然后在里面你可以根据需要使用任意数量的 Grid 和属性项。
But inside of Grid with property item you should have only items(Componets like Typography, Button, Avatar or whatever component you have) and not more Grids.但是在带有属性项的网格内部,您应该只有项目(如排版、按钮、头像或您拥有的任何组件等组件)而不是更多网格。
So your code should be something like:所以你的代码应该是这样的:
<React.Fragment>
<CssBaseline />
<ThemeProvider theme={theme}>
<Grid container direction='column'>
<Grid item >
<Header/>
</Grid>
</Grid>
<Grid container>
<Grid item xs={12} sm={8}>
<Switch>
<Route path="/bouquets">
<Bouquets />
</Route>
<Route path='/about'>
<About />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Grid>
<Grid/>
</ThemeProvider>
</React.Fragment>
I hope I have clarified how to use the container or item property in the component and that it helps you to solve your warning.我希望我已经阐明了如何在组件中使用 container 或 item 属性,并且它可以帮助您解决您的警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.