简体   繁体   English

如何修复“失败的道具类型:`grid` 的属性`spacing` 必须用于`container`?

[英]How to fix "Failed prop type: The property `spacing` of `grid` must be used on `container`?

I am currently working on a project in which I utilize React and the Material-UI framework.我目前正在做一个项目,在这个项目中我使用了 React 和 Material-UI 框架。 However, after using grid an error pops up saying:但是,使用 grid 后会弹出一个错误消息:

checkPropTypes.js:20 Warning: Failed prop type: The property `spacing` of `Grid` must be used on `container`.
    in WithStyles(ForwardRef(Grid)) (created by NavBar)
    in NavBar (created by Root)
    in Root

I have already checked all of my code and the Grid container does use the spacing prop.我已经检查了我的所有代码,并且 Grid 容器确实使用了spacing道具。 I have also tried removing spacing from Grid item and this causes more errors.我还尝试从 Grid 项目中删除间距,这会导致更多错误。

<BrowserRouter>
      <AppBar position="static">
        <Toolbar style={navStyle}>
          <Grid
            justify="space-between"
            container
            spacing={10}
          >
            <Grid
              item
              spacing={2}
            >
...

Everything is showing up on the screen properly, however;然而,一切都正确地显示在屏幕上; this error still pops up.这个错误仍然弹出。 I am unsure how to fix this and would love to learn!我不确定如何解决这个问题,很想学习!

You can't put spacing prop on an item grid.您不能在项目网格上放置间距道具。

Just try to remove the spacing={2}只需尝试删除spacing={2}

And take a look on the Grid API MUI并查看 Grid API MUI

spacing : Defines the space between the type item component.间距:定义类型项组件之间的间距。 It can only be used on a type container component.它只能用于类型容器组件。

There seems to be some confusion about Grid that caught me too;似乎也有一些关于Grid 的困惑也吸引了我;

Container容器

  • spacing={number} (number ranging from 0 to 9)间距={number}(数字范围从 0 到 9)

Item物品

  • Usually used within containers通常在容器内使用
  • Sizing similar to Css Grid is provided (xs={12} sm={6} )提供类似于 Css Grid 的大小 (xs={12} sm={6} )

But You can use Item & Container altogether...但是您可以完全使用 Item & Container...

<Grid container item xs={12} spacing={3}>
    ....
</Grid>

Remove spacing={2}删除spacing={2}

To use spacing you can try ``containers要使用spacing您可以尝试 ``containers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 失败的道具类型:必须在容器上使用 Grid 的道具 justify - Failed prop type: The prop justify of Grid must be used on container MUI v5:失败的道具类型:`Grid` 的道具`direction` 只能与`container` 道具一起使用 - MUI v5: Failed prop type: The prop `direction` of `Grid` can only be used together with the `container` prop 如何修复警告:道具类型失败 - How to fix Warning: Failed prop type 反应如何修复失败的道具类型 - 类型字符串预期对象的无效道具 - React How to fix Failed prop type - Invalid prop of type string expected object 失败的道具类型:提供给“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)` 失败的道具类型:“值”必须在 InputRange 的“minValue”和“maxValue”之间 - Failed prop type: "value" must be in between "minValue" and "maxValue" at InputRange 警告:失败的道具类型:游戏:道具类型`游戏`无效; 它必须是一个函数,通常来自React.PropTypes - Warning: Failed prop type: Game: prop type `game` is invalid; it must be a function, usually from React.PropTypes 失败的道具类型:聊天:道具类型`房间`无效; 它必须是一个函数,通常来自React.PropTypes - Failed prop type: Chat: prop type `room` is invalid; it must be a function, usually from React.PropTypes 警告:失败的道具类型:提供给“ForwardRef(网格)”的无效道具“xs” - 材质 UI 网格中的错误 - Warning: Failed prop type: Invalid prop `xs` supplied to `ForwardRef(Grid)` - Error in Material UI Grid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM