简体   繁体   English

警告:失败的道具类型:提供给“ForwardRef(网格)”的无效道具“xs” - 材质 UI 网格中的错误

[英]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.

相关问题 失败的道具类型:提供给“ForwardRef(Grid)”的无效道具“children” - Failed prop type: Invalid prop `children` supplied to `ForwardRef(Grid)` 失败的道具类型:提供给“ForwardRef(Grid)”的无效道具“lg” - Failed prop type: Invalid prop `lg` supplied to `ForwardRef(Grid)` 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)` 道具类型失败:当我打开 Material UI 菜单时,提供给 `ForwardRef(Portal)` 的道具 `container` 无效 - Failed prop type: Invalid prop `container` supplied to `ForwardRef(Portal)` when I open Material UI menu 警告:道具类型失败:提供给“ForwardRef(FormControl)”的“string”类型的道具“error”无效,预期为“boolean” - Warning: Failed prop type: Invalid prop `error` of type `string` supplied to `ForwardRef(FormControl)`, expected `boolean` 警告:道具类型失败:提供给“ForwardRef(Dialog)”的“function”类型的无效道具“open”,应为“boolean”。 在对话框 - Warning: Failed prop type: Invalid prop `open` of type `function` supplied to `ForwardRef(Dialog)`, expected `boolean`. at Dialog 警告:失败的道具类型:提供给“ForwardRef(Select)”的无效道具“children”,需要一个ReactNode - Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef(Select)`, expected a ReactNode React Native +图标:警告:失败的道具类型:无效的props.style键tintColor提供给ForwardRef(Text) - React Native + Icons: Warning: Failed prop type: Invalid props.style key tintColor supplied to ForwardRef(Text) 反应警告:失败的道具类型:提供的“对象”类型的无效道具 - React Warning: Failed prop type: Invalid prop of type `Object` supplied 警告:道具类型失败:提供给“路线”的道具属性无效。 在途中 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. in Route
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM